What are named routes in Laravel?

Written by Vernie

Posted On: Jan 11, 2019


    1 Answer Written

  •  Vernie
    Posted by Shashank Garg

    Named routing is another amazing feature of the Laravel framework. Named routes allow referring to routes when generating redirects or URLs more comfortably. You can specify named routes by chaining the name method onto the route definition:


    Route::get('user/profile', function () {

    You can specify route names for controller actions:

    Route::get('user/profile', 'UserController@showProfile')->name('profile');

    Once you have assigned a name to your routes, you may use the route's name when generating URLs or redirects via the global route function:

    // Generating URLs...
    $url = route('profile');
    // Generating Redirects...
    return redirect()->route('profile');

    Source: http://www.laravelinterviewquestions.com/2017/07/named-routes-laravel.html

Please Login or Register to leave a response.

Related Questions