Laravel 5.1.26+中第三方用户管理的Gate功能出现问题


Trouble with Gate feature with third party user management in Laravel 5.1.26+

我正试图将我们的SSO(单点登录解决方案)集成到一个老式的laravel应用程序中,升级到5.1.26后,我想尝试ACL解决方案,但遇到了问题。我已经添加了一个基本的能力来尝试这个,但它不起作用,我想帮助解决它

<?php
namespace App'Providers;
use Auth;
use Illuminate'Contracts'Auth'Access'Gate as GateContract;
use Illuminate'Foundation'Support'Providers'AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
    public function boot(GateContract $gate){
        $this->registerPolicies($gate);
        $gate->define('create-report', function ($userRoles) {
            return in_array('super_admin', $userRoles);
        });
    }
    public function register()
    {
        //
    }
}

我用试试这个

if('Illuminate'Support'Facades'Gate::allows('create-report', $roles)){
    dd("This never happens");
} else {
    dd("This always happen!");
}

我需要"让我的用户登录"吗?由于我们有中央用户管理系统,我从不处理应用程序中的任何用户。我只有一个用户对象(从sso-api获取)保存在会话变量中。

"当没有经过身份验证的用户或没有使用forUser方法指定特定用户时,所有能力的Gate都会自动返回false。"

Laravel-授权-定义能力