向 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屋!
查看全文