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

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

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'taylor@laravel.com',
        ]);
    });
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
黄威
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 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年前 评论

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