我有UsersController.php
$this->beforeFilter('permission:administration');
并在我的filers.php中(这是为了幼虫3我想将它改为幼虫4.2当量)
Route::filter('permission', function($permission)
{
if(!Auth::user()->permission($permission)) return App::abort(500);
});
此代码来自Laravel 3,我正在尝试为Laravel 4.2做同样的事情我正在遇到以下错误:
Object of class Illuminate\Routing\Route could not be converted to string
我怎么能解决这个问题,请帮忙
答案 0 :(得分:0)
这可以在routes.php或controller中完成。
在控制器中:
$this->beforeFilter('permission:administration');
在routes.php文件中:
Route::group(['before' => 'permission:administration'], function() {
Route::get('my-route', 'UsersController@action');
});
或
Route::get('my-route', ['before' => 'permission:administration', 'uses' => 'UsersController@action'])
要检索“管理”值:
Route::filter('permission', function($route, $request, $permission)
{
if(!Auth::user()->permission($permission)) return App::abort(500);
});