Laravel 5 Hello Word application

Hello, guys, we all know about Laravel framework. Laravel is the most popular Object-oriented PHP framework. Let’s see the “Hello Word” Example of Laravel step by step. Let’s see the first step for install Laravel using Composer.

composer create-project --prefer-dist laravel/laravel example

If you want to install the custom version of Laravel use below command.

composer create-project --prefer-dist laravel/laravel example "5.4.*"

Now, wait for some moment still Laravel installation is not finished.

After finish Laravel installation goto the Laravel project directory.

cd example

Now Run Laravel project using below command.

php artisan serve

Let run your Laravel project using below link ( Make sure your Apache server is running ).

http://localhost:8000

Now let’s see how to create new ‘controller’ and print the “Hello Word”. First of all, let’s create a route.

If you installed Laravel above or 5.3 open route file from “routes/web.php” or you installed Laravel below or 5.2 open route file from “app/Http/routes.php” file.

Route::get('/hello-word', 'ExampleController@index');

Let’s have some knowledge about route Route::get means the GET method of URL and the ‘/hello-word’ is the slug for the URL and ExampleController@index means “ExampleController” is the name of our Controller and “index” is the name of Controller Method.

Let’s create first Controller file at “app/Http/Controllers/ExampleController.php” file and open it.

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ExampleController extends Controller
{
    public function index(Request $request){
       return view('example');
    }
}

Now, Create a view file for our controller at “resources/example.blade.php” file.

<h1>Hello Word</h1>

let’s awesome we finished the first Laravel application from step by step. it’s too easy to learn Laravel framework.

Now, let’s open below URL on your browser for output.

http://localhost:8000/hello-word

If you have any question about Laravel or you face any issue after using this article please write a comment.