Get route name in laravel

    By: Manu
    2 years ago

    Ok So we can use this if you are using laravel 5.8 or above.

    This will return route name make sure you have a route name set for route you are checking for.
    
    if(request()->route()->getName() == 'blog')
    {
       // Do something;
    }
    


    In web.php route defined as

    Route::get('/blog',[
        'uses' => 'BlogController@index',
        'as' => 'blog' // here we defined route name.
    ]);
    


    Hope this helps