我正在使用 Restful Controller 。我需要对它们运行一些过滤器,例如身份验证和自定义权限。所以我把它们放在一个路由组中,并在该组上设置过滤器。此外,我还想运行 csrf 过滤器,但仅限于发布请求。如何在路由组中做到这一点?
添加代码以进行说明
Route::group(array('before' => 'auth|allowed|csrf'), function() {
Route::controller('controller', 'SomeController');
Route::controller('othercontroller', 'OtherController');
});
我只想在邮寄路线上使用 csrf。我真的不想在每个 Controller 上都添加过滤器(有很多);
最佳答案
在使用resourceful routing 时,您可以从 Controller 执行此操作。
public function __construct() {
$this->beforeFilter('csrf', array('on' => 'post'));
}
关于路由组上的 Laravel 过滤器,但仅在发布请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18900130/