使用Entrust的Laravel 5.2 - 无法检查权限并呈现403

时间:2016-08-09 12:44:13

标签: php laravel-5.2 entrust

我是Laravel的新手,我正在使用User,Roles ans Permission开发应用程序。为此,我使用Zizaco / Entrust。我几乎完成了所有步骤,但我无法显示403的自定义页面。我的代码如下:

Permission : role-list
Role : Manager

'role-list'被分配到' manager'角色,然后'manager'角色被分配到' ABC'用户。

在我的app \ kernel file id中添加了这些中间件:

protected $routeMiddleware = [
        'auth' => \Eybos\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \Eybos\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
        'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
        'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
    ];

在我的路线档案中:

Route::get( 'backend/roles', [ 'as' => 'backend.roles.index', 'uses' => 'Backend\RoleController@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 Symfony\Component\HttpKernel\Exception\HttpException

1 个答案:

答案 0 :(得分:0)

不确定这是否是正确的答案,但是......

转到Lewis-&gt; presenter-&gt; src-&gt; Decorator.php

第80行的

你应该看到“$ object = clone $ object;”

注释掉行,它应该开始使用权限。