get route laravel code example

Example 1: laravel get current route name

Route::currentRouteName()

Example 2: laravel get current route name

Route::getCurrentRoute()->getActionName();

Example 3: laravel route namespace and prefix

Route::name('admin.')->group(function () {
    Route::get('/users', function () {
        // Route assigned name "admin.users"...
    })->name('users');
});

Example 4: laravel route

# Using Request
Route::get('user/{name}', function (Request $request) {
    return $request->route('name');
});

Example 5: set route name laravel

Route::get('/novanoticia', 'HomeController@getNovaNoticia')->name('route_name');

Example 6: laravel route

Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
    //
});

Tags:

Php Example