简体   繁体   中英

Laravel - Get route name in filter

How can I get current route name in filter? I tried use Route::currentRouteName(); but it's null.

Route::filter('belongsToUser', function(){
    dd( Route::currentRouteName() );
    exit;
});

Route looks for example:

Route::get('/openTicket/{id}', array('before' => 'auth|belongsToUser', 'uses' => 'MyController@MyAction'));

Your route isn't named, so it's no surprise the route name is null. You need an as parameter.

Route::get('/openTicket/{id}', array(
  'as' => 'yourRouteName',
  'before' => 'auth|belongsToUser',
  'uses' => 'MyController@MyAction'));

http://laravel.com/docs/routing#named-routes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM