我是Laravel的新手,我正在开发一个具有用户,角色和权限的应用程序。我用的是Zizaco/Entrust。我几乎完成了所有的步骤,但是我无法显示403的自定义页面。我的代码如下:
Permission : role-list
Role : Manager
将'role-list'
分配给' manager'
'角色,然后将'manager'
角色分配给'ABC'用户。
在我的应用程序内核文件id添加这些中间件:
protected $routeMiddleware = [
'auth' => EybosHttpMiddlewareAuthenticate::class,
'auth.basic' => IlluminateAuthMiddlewareAuthenticateWithBasicAuth::class,
'can' => IlluminateFoundationHttpMiddlewareAuthorize::class,
'guest' => EybosHttpMiddlewareRedirectIfAuthenticated::class,
'throttle' => IlluminateRoutingMiddlewareThrottleRequests::class,
'role' => ZizacoEntrustMiddlewareEntrustRole::class,
'permission' => ZizacoEntrustMiddlewareEntrustPermission::class,
'ability' => ZizacoEntrustMiddlewareEntrustAbility::class,
];
在我的路由文件:
Route::get( 'backend/roles', [ 'as' => 'backend.roles.index', 'uses' => 'BackendRoleController@index', 'middleware' => ['permission:role-list|role-create|role-edit|role-delete']] );
然后创建一个文件:resources/views/errors/403.blade.php
@extends('layouts.backend')
@section('content')
<h1>You don't have permission.</h1>
@endsection
但是当我尝试访问页面时,我得到这个错误:
FatalErrorException in Decorator.php line 80:
Trying to clone an uncloneable object of class SymfonyComponentHttpKernelExceptionHttpException
不确定这是否是正确的答案,但是…
打开Lewis->presenter->src->Decorator.php
在第80行你应该看到"$object = clone $object;"
注释掉这行,它应该开始使用权限。