在写入用户的特权和权限时显示错误:inner_content
控制器代码
403
Forbidden
AuthServiceProvider代码
class IndexController extends AdminController
{
public function __construct(){
parent::__construct();
if (Gate::denies('VIEW_ADMIN')) {
abort(403);
}
$this->template = env('THEME').'.admin.index';
}
模型用户代码
public function boot()
{
$this->registerPolicies();
Gate::define('VIEW_ADMIN', function($user){
return $user->canDo('VIEW_ADMIN');
});
//
}
模型与User
模型关联,而Roles
模型与Roles
模型关联。
Permission
答案 0 :(得分:0)
您在行$permission
上重写了输入foreach ($this->permissions as $permission) {
,因此您的if (str_is($permission,$permission->name))
始终为假
因为
str_is(array(), 'VIEW_ADMIN') === FALSE
您应该这样做
public function canDo($permission, $require = FALSE){
if (is_array($permission)) {
dump($permission);
}
else{
foreach ($this->roles as $role) {
foreach ($this->permissions as $permissionObject) {
if (str_is($permission,$permissionObject->name)) {
return true;
}
}
}
}
}
此外,您还应该添加返回假,因为在这种情况下返回类型为布尔。