我有2个表格:角色和用户。
在用户中,我具有role_id,并且我想检查该角色的true上是否包含一列“ access_admin_area”。如果为true,则表示我在使用中间件。
Gate::define('admin', function ($user) {
return !empty($user->roles()->where('access_admin_area', true)->first());
});
从用户模型:
public function roles()
{
return $this->hasOne(Role::class);
}
SQLSTATE [42703]:未定义的列:7错误:列role.user_id不存在↵LINE1:从“ roles”中选择*,其中“ roles”。“ user_id” = $ 1和“ role ..