简体   繁体   中英

Laravel 5 custom named routes in resource controllers

How can I pass in my own extra named routes for a resource controller?

I have:

Route::resource('logistics', 'LogisticsController', ['names' => [
    'index-inbound' => 'logistics.indexInbound'
]]);

But this does not work.

You can't really add additional routes to a resource route. However, you can add any other routes you want and point them to the same controller:

Route::get('logistics/inbound', ['name' => 'logistics.index-inbound', 'uses' => 'LogistictsController@indexInbound']);
Route::resource('logistics', 'LogisticsController');

Just make sure that you register your custom routes before the resource route as otherwise they might get overridden.

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