如何使用 Entrust 为 Frozennode 管理员验证角色

How to authenticate Role with Entrust for Frozennode Administrator

我正在使用 Confide (v3.2) and Entrust(v1.2) with Frozennode Administrator。在配置文件中有一个选项,我需要设置它 return true/false 取决于用户是否通过身份验证。

/**
 * The permission option is the highest-level authentication check that lets you define a closure that should return true if the current user
 * is allowed to view the admin section. Any "falsey" response will send the user back to the 'login_path' defined below.
 *
 * @type closure
 */
'permission'=> function()
{
    return Auth::check();
},

它正在使用默认值Laravel Auth:check();我使用 confide Confide 对用户进行身份验证,但它只是验证任何用户是否已通过身份验证,我需要确保他们具有管理员角色才能使用管理员。我正在使用 Entrust 作为角色,并希望获得等效的。我只在文档中看到 Entrust to use

$user->hasRole("Admin");

但我知道这是行不通的,因为 $user 没有定义。我该怎么做?

我不熟悉你使用的包,但如果你可以使用 Auth::check(),你可能也可以使用 Auth::user()->hasRole('Admin') 来获取当前用户的状态并从那里开始。