create-hello-world-app-with-laravel

Create Hello World app with laravel

Hello World, Welcome to the Learn Laravel with example. In the first tutorial of this series, in the previous tutorial, we have learned that what is laravel and what will we create with laravel in this series. In this tutorial we will setup laravel on our local environment and create hello world app with laravel.

We will learn the following things in this tutorial.

  • Setup laravel on localhost environment
  • Create hello world app

Setup laravel on local environment

  • Open your command line or terminal and goto to server folder where your localhost files are running and then type the following command
    composer create-project laravel/laravel todo
    
  • In the above command we are using composer command. Composer is php dependency management tool. You can read about composer from this link.

With the help of above command, Laravel will be installed on your targeted folder in which you have run this command. Most of the work in this tutorial series will be done by command line.

Open the url with folder name in which laravel has been installed and then click on the public folder. If everything is ok then you will see the following screenshot.

first-screen

 

Now we have installed laravel on our local system. It’s time to create hello world app. We know that laravel is based on MVC pattern. So firstly we will create controller for our app and then view. We are not working with model because there is no need for database in this hello world app.

Create controller with laravel

  • Run the following command for creating controller in laravel
php artisan make:controller TodoController

Above command will create controller file in the following folder in laravel.

app/Http/Controller/TodoController.php

Open this file and add following function in this class.

function hello_world(){
        return view('hello_world');
    }

In the above function, we are calling view file hello_world.

Create View

Now we will create the view for our hello world app. Laravel provide the blade template engine which help us to reduce our efforts and time. You can read about blade template engine from this link. Create  hello_world.blade.php file in following folder.

/resources/views/

In hello_world.blade.php, Add the following content.

<!DOCTYPE html>
<html>
<head>
	<title>Hello World App</title>
</head>
<body>
	<h1>This is hello world app</h1>
</body>
</html>

Configure the route

For open the hello world app in browser, we have to make route configuration. Open the following file.

/routes/web.php

Add the following code in the above file.

Route::get('hello_world','TodoController@hello_world');

Open the following url in browser and you will see the following screen.

http://localhost/todo/public

app

Leave a Reply