PHP LARAVEL - Hello World Laravel
As part of a new assignment, I have started working on Laravel. After completing the setup, I am writing my first program on Laravel. I am not different from other programmers, so I am starting with the basic Hello world, and it works as sanity test to make sure that application has been installed correctly.
Let's how we can write Hello World in Laravel.
Through Route
In your Laravel project, go to routes/web.php file and add the following chunk of code:
Route::get('/', function () {
return 'Hello World!';
});
Through Controller
Now we will create a new controller with the artisan command:
Go to the project root folder through command prompt and execute below the command.
php artisan make:controller HelloWorldController
Now go to your controller folder /app/Http/Controllers, you can see HelloWorldController.php and add the following function
public function helloWorld(){Now to use the controller to display the message, update routes/web.app file.
return 'Hello World from controller!!!';
}
Route::get('/', 'HelloWorldController@helloWorld');
Now run the application in the browser, you will get Hello World from controller!!!
Happy Programming..!!!
Comments
Post a Comment