First MVC Hello world in Laravel

In order to create a custom MVC in laravel we have to define :

  1. route of the request
  2. controller for request handling
  3. view for generating HTML

Step 1 (defining route in ‘routes.php’)


| Application Routes
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.

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

Route::get('home', 'HomeController@index');

	'auth' => 'Auth\AuthController',
	'password' => 'Auth\PasswordController',

/* 'helloMVC' if the request url, 'MVCController' if the name of the class which handles  
	request and 'index' if the name of the method responsible for handling request */
Route::get('helloMVC', 'MVCController@index');

Step 2 (adding controller class ‘MVCController.php’)

<?php namespace App\Http\Controllers;

class MVCController extends Controller {

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

Step 2 (creating view ‘MVCView.php’)

	<title>first MVC Laravel</title>
	Hello Content


URL Requested : laravel/public/helloMVC
Output : Hello Content

Directory Structure



You may also like...