问题标签 [laravel-gate]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
90 浏览

laravel-8 - 传递给 App\Models\User::hasAnyRoles() 的参数 1 必须是数组类型,给定字符串

我想限制管理员访问某些页面并在运行我的代码后收到此错误:传递给 App\Models\User::hasAnyRoles() 的参数 1 必须是数组类型,给定字符串,在 F:\Main Server 中调用\htdocs\voskillproject\app\Providers\AuthServiceProvider.php 在第 33 行(查看:F:\Main Server\htdocs\voskillproject\resources\views\backend\adminsidebar.blade.php)

这是我的用户模型

这是我的 authserviceprovider,我在其中注册了我的大门

这是导航栏部分

我不明白我的代码哪里做错了

0 投票
0 回答
149 浏览

php - Laravel Gates 使用模型并返回“不在对象上下文中使用 $this”AzureUser 模型的第 28 行

我试图在 Laravel 中创建一个 Gate。这个想法是检查 AzureAD 访问令牌上是否存在角色之一。

到目前为止我有这个

到目前为止,响应是“不在对象上下文中使用 $this”。

门和模型的错误

这是完整的代码

AuthServiceProvider -> 路径 app\Providers

AzureUser 模型-> 应用\模型

路线

任何想法为什么不检测模型?谢谢!

0 投票
1 回答
26 浏览

php - laravel 中门和中间件的主要区别是什么?

各位,我只想问一个非常明确的问题。我知道这是用于对用户进行身份验证的中间件,但门和策略会根据他/她的角色来限制用户行为。如果用户未通过身份验证,我使用 LARAVEL gates 将用户重定向到登录页面所以,问题是:LARAVEL 中间件是否包含 Gates 或什么?谢谢先进。