起初似乎是相同的路线。但在第一条路径中,我在构造函数中订购了不工作的中间件。
如何解决?
Route::get('/cars.get', function() {
return App::make('App'Http'Controllers'CarsController')->{'get'}();
});
Route::get('/cars.get', 'CarsController@get');
对不起我的英语=)
编辑
我错了callAction()
,它只调用方法。遗憾的是,似乎并没有一个简单的API来手动调用中间件。解决这个问题的方法就是定义路由上的中间件:
Route::get('/cars.get', ['middleware' => 'auth', function() {
return App::make('App'Http'Controllers'CarsController')->{'get'}();
}]);
原始答案:
通过直接调用get()
方法,可以跳过控制器中定义的中间件。您应该使用callAction()
:
return App::make('App'Http'Controllers'CarsController')->callAction('get');
还要注意,您可以使用app()
作为App::make()
:的快捷方式
return app('App'Http'Controllers'CarsController')->callAction('get');