在Laravel中向资源控制器添加新方法 [英] Add new methods to a resource controller in Laravel
本文介绍了在Laravel中向资源控制器添加新方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能在Laravel中向资源控制器添加新方法,以及如何实现.
I want to know if it is possible to add new methods to a resource controller in Laravel and how you do it.
我知道这些方法是默认方法(索引,创建,存储,编辑,更新,销毁).现在,我想向同一控制器添加其他方法和路由.
I know that these methods are the default (index, create, store, edit, update, destroy). Now I want to add additional methods and routes to the same controller.
有可能吗?
推荐答案
只需在注册资源之前分别向该方法添加路由:
Just add a route to that method separately, before you register the resource:
Route::get('foo/bar', 'FooController@bar');
Route::resource('foo', 'FooController');
这篇关于在Laravel中向资源控制器添加新方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文