Menu

Naming routes in Laravel

In some cases, it can be extremely useful to give an id or name to our routes, and Laravel makes it the easiest thing in the world.

Here is how to name a route in your routes.php file.

Route::get('/home', '[email protected]')->name('home');

or

Route::get('/home', ['as' => 'home', 'uses' => '[email protected]']);

This is how you can reference your named route, and you get the full URL with the route:

$url = route('home');

 

Documentation: https://laravel.com/docs/5.2/routing#named-routes

Have something on your mind?