【问题标题】:Laravel Telescope is not working in production with Laravel Voyager. How to secure /telescope/* routes in Laravel 7?Laravel Telescope 没有与 Laravel Voyager 一起工作。如何在 Laravel 7 中保护 /telescope/* 路线?
【发布时间】:2020-11-07 13:54:11
【问题描述】:
我将 Laravel 与 Auth、Auth UI、Voyager 管理面板、Telescope 结合使用。一切正常,直到我在 .env 文件中将 APP_ENV=local 更改为 APP_ENV=production。当我将 .env 文件更改为生产时,我收到以下错误。我的问题的屏幕截图是here。
试图获取非对象的属性“名称”
基本上我想在生产中保护/telescope/*routes。但在这样做之前,我收到了这个错误。
我在 github similar issue github link 中阅读了同样的问题。我认为答案存在于链接中,但作为新手,我无法消化它。
任何帮助解决这个问题,并在生产中保护望远镜路线都非常感谢。我试图创建一个策略并通过策略向用户授予读取权限。但不知何故我无法修复它。
【问题讨论】:
标签:
production
laravel-7
voyager
【解决方案1】:
好的:这太容易了——你唯一要做的就是:
php artisan make:policy -m User UserPolicy
就是这样。
【解决方案2】:
您可以将电子邮件数组传递给TelescopeServiceProvider.php中的gate方法
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'username@domain.com'
]);
});
这将阻止除登录用户提到的电子邮件之外的所有人。