Telescope 在生产环境配置的权限,还是弹出 403 页面

原来是从Laravel5.3版本 一路升级上来的,现在版本是5.7

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'taylor@laravel.com',
        ]);
    });
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
黄威
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

几年前的坟挖一下, 顺便记录一下
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, [
                //
            ]);
        });
    }
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!