讨论数量:
几年前的坟挖一下, 顺便记录一下
TelescopeApplicationServiceProvider
方法1
/**
* Configure the Telescope authorization services.
*
* @return void
*/
protected function authorization()
{
$this->gate();
Telescope::auth(function ($request) {
// 此处修改你的判断逻辑
return true;
return app()->environment('local') ||
Gate::check('viewTelescope', [$request->user()]);
});
}
方法2
- 使用可空类型提示或将默认值设置为null来允许访客进行授权检查
- function (?User $user) 或 function ($user=null)
/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewTelescope', function (?User $user) {
return true;
return in_array($user->email, [
//
]);
});
}
推荐文章: