我正在尝试在运行Laravel 5.2的应用程序中使用Entrust ACL。我按照Entrust的GitHub页面上的说明安装了软件包,一切顺利。
我在routes.php中添加了这个路由组
Route::group(['namespace' => 'Backend', 'prefix' => 'admin', 'middleware' => ['auth']], function () {
Route::get('roles',['as'=>'roles','uses'=>'RoleController@index','middleware' => ['permission:role-list|role-create|role-edit|role-delete']])->name('admin.roles');
Route::get('roles/create',['as'=>'roles.create','uses'=>'RoleController@create','middleware' => ['permission:role-create']])->name('admin.roles.create');
Route::post('roles/create',['as'=>'roles.store','uses'=>'RoleController@store','middleware' => ['permission:role-create']])->name('admin.roles.create');
});
这是我的RoleController
class RoleController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$roles = Role::orderBy('id','DESC')->paginate(5);
return view('backend.roles.index',compact('roles'))->with('i', ($request->input('page', 1) - 1) * 5);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$permission = Permission::get();
return view('backend.roles.create',compact('permission'));
}
}
查看文件位于resources/views/backend/roles/
。我认为路线有问题,但无法理解。
当我尝试打开http://localhost/admin/roles
时,我遇到了这个错误:
Application.php第905行中的HttpException:
在Application.php第905行
在Application-> helpers.php第30行中的abort('403','',array()) 在EntrustPermission.php第39行的中止('403')
at EntrustPermission-> handle(object(Request),object(Closure),'role-list | role-create | role-edit | role-delete')
at call_user_func_array(array(object(EntrustPermission),'handle'),array(object(Request),object(Closure),'role-list | role-create | role-edit | role-delete'))in Pipeline.php第136行
知道我在这里做错了吗?
现在我的观点中有Route [roles.create] not defined.
:
@permission('role-create')
<a class="btn btn-success" href="{{ route('roles.create') }}"> Create New Role</a>
@endpermission
答案 0 :(得分:1)
首先必须附加role_id和user_id,中间件应该像
'middleware' => ['auth','admin']