Routing in Laravel 5

 

What is routing?

Routing is essential part of MVC because in MVC we don’t have physical files to redirect the different requests unlike web forms applications. Routing is a mechanism in MVC which defines a way to our application and tell which action method(like get and post) of a controller class to execute.

Creating Routes

Routes should be created in routes.php(app/Http/routes.php ) file, This file is loaded by RouteServiceProvider( App\Providers\RouteServiceProvider which loaded from routing request ) class.

Get Route:

<?php

Route::get('home', function(){
	return 'some response';
})

 

here get defines method name and home is first parameter which is route URL path and second parameter is anonymous function which returns some data that will be displayed when this route is called, Usually we return View from here.

<?php

Route::post('home', function(){
	return 'something';
})
Route::put('home/{home}', function(){			    // Update record
	//
})
Route::delete('home/{home}', function(){			// Delete Record
	//
})

Something to say? Tell us in comment section.