Files
stuart-craig-removals/app/Providers/TelescopeServiceProvider.php
Shaun Collins 646041230b Init
2026-03-04 16:34:33 +00:00

66 lines
1.7 KiB
PHP

<?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.
*/
public function register(): void
{
$this->hideSensitiveRequestDetails();
$isLocal = $this->app->environment('local');
$recordAll = config('telescope.record_all');
Telescope::filter(function (IncomingEntry $entry) use ($isLocal, $recordAll) {
return $isLocal ||
$recordAll ||
$entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}
/**
* Prevent sensitive request details from being logged by Telescope.
*/
protected function hideSensitiveRequestDetails(): void
{
if ($this->app->environment('local')) {
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.
*/
protected function gate(): void
{
Gate::define('viewTelescope', function ($user = null) {
$allowed = explode(',', config('telescope.allowed_ips'));
return in_array(request()->ip(), $allowed);
});
}
}