Laravel 5 Tutorial (03) :: Make controller and view for insert and show data (Part 1)

Today we’ll make a controller for handle our model and view. We’ll make a controller name with TodoController. Let’s see the simple steps

You can read previous posts


Follow the steps

  1. Go to your htdocs folder and right click on TODO folder by pressing ctrl+shift key and open command window
  2. Type php artisan make:controller TodoController and press enter
    If you successfully create controller a file you will get in your project directory (app/Http/Controllers) name with TodoController.php

Now open the routes.php file from app/Http directory and write code like below.

Route::get('/', 'TodoController@index');

Screenshot :

Now go to Resources/views directory and replace code in app.blade.php

<link href="/css/app.css" rel="stylesheet">

replace with

<link href="{{asset('/css/app.css')}}" rel="stylesheet">

Aim : We’ll write code for when a user browse our application’s root directory it’ll show a view page with TodoController.
Open the TodoController.php file and go to index method and write code in index method

public function index()
  return view('home');

This index method will call the home.blade.php view from the resources/views folder. Here we don’t have to write the .blade.php extension, we have to just write the view name, laravel will automatically detect the actual view file. Now browse the address http:://localhost/todo/public/

In next tutorial we will make a form in our home.blade.php view file for insert data, and retrieve data from database.

Tags : , , , , , , , ,

Share on :

Leave a Reply

5 + two =