【问题标题】:Laravel 5.2 with Entrust - not able to check Permission and render 403带有 Entrust 的 Laravel 5.2 - 无法检查权限并呈现 403
【发布时间】:2016-12-15 12:32:15
【问题描述】:

我是 Laravel 的新手,我正在开发一个具有用户、角色和权限的应用程序。为此,我使用 Zizaco/Entrust。我几乎完成了所有步骤,但我无法显示 403 的自定义页面。我的代码如下:

Permission : role-list
Role : Manager

'role-list' 分配给“manager'”角色,然后将'manager' 角色分配给“ABC”用户。

在我的 app\kernel 文件 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

【问题讨论】:

    标签: php laravel-5.2 entrust


    【解决方案1】:

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

    转到 Lewis->presenter->src->Decorator.php

    在第 80 行你应该看到“$object = clone $object;”

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-19
      • 2017-02-06
      • 2016-10-19
      • 2016-10-22
      • 2016-12-04
      • 2016-06-27
      • 2019-10-28
      • 2016-11-15
      相关资源
      最近更新 更多