我正在 laravel 4 中构建一个宁静的 api,其中有具有不同类型权限的用户。我想根据用户角色限制对不同路由的访问(保存在数据库的用户表中)
我该怎么做?这是我到目前为止所拥有的(到目前为止还没有工作)。
过滤器.php
//allows backend api access depending on the user's role once they are logged in
Route::filter('role', function()
{
return Auth::user()->role;
});
路由.php
Route::group(array('before' => 'role'), function($role) {
if($role==1){
Route::get('customer/retrieve/{id}', 'CustomerController@retrieve_single');
Route::post('customer/create', 'CustomerController@create');
Route::put('customer/update/{id}', 'CustomerController@update');
}
});
是否有可能我为“组过滤器”编写了错误的语法?