我已经实现了 Laravel Telescope,我只能在以下情况下访问 APP_ENV=local
我遵循了 Laravel 的文档并更改了代码TelescopeServiceProvider.php(注意我的环境被称为 loca、dev、testing 和 prod)。
我可以访问的唯一方法Telescope是APP_ENV=local在每个环境中进行更改。
有谁知道哪个可能是问题?
问候
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// Telescope::night();
$this->hideSensitiveRequestDetails();
Telescope::filter(function (IncomingEntry $entry) {
if ($this->app->environment('local') || $this->app->environment('dev') || $this->app->environment('test') || $this->app->environment('prod')) {
return true;
}
return $entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}
/**
* Prevent sensitive request details from being logged by Telescope.
*
* @return void
*/
protected function hideSensitiveRequestDetails()
{
if ($this->app->environment('local') || $this->app->environment('dev') || $this->app->environment('test') || $this->app->environment('prod')) {
return;
}
Telescope::hideRequestParameters(['_token']);
Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}
/**
* 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) {
return in_array($user->email, [
//
]);
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的confif/app.php文件
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
//App\Providers\TelescopeServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
Run Code Online (Sandbox Code Playgroud)
Wah*_*nto 11
默认情况下,您将只能在local环境中访问此仪表板。
在您的app/Providers/TelescopeServiceProvider.php文件中,有一种gate方法。此授权门控制在非本地环境中对 Telescope 的访问。您可以根据需要自由修改此门以限制对 Telescope 安装的访问:
/**
* 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) {
return in_array($user->email, [
// Your users
'user@yourapp.tld',
]);
});
}
Run Code Online (Sandbox Code Playgroud)
您可以覆盖您的authorization()方法并包含您的环境名称。Laravel\Telescope\TelescopeApplicationServiceProviderApp\Providers\TelescopeServiceProvider
但要小心。
/**
* Configure the Telescope authorization services.
*
* @return void
*/
protected function authorization()
{
$this->gate();
Telescope::auth(function ($request) {
return app()->environment('local') ||
Gate::check('viewTelescope', [$request->user()]);
});
}
Run Code Online (Sandbox Code Playgroud)
到
...
return app()->environment(['local', 'testing']) ||
Gate::check('viewTelescope', [$request->user()]);
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3567 次 |
| 最近记录: |