In Laravel Telescope, by default, only the local environment is allowed to access the dashboard. To modify this restriction in non-local environments, you can edit the gate
method within the app/Providers/TelescopeServiceProvider.php
file.
Here's an example of how you can modify the gate
method to control access:
/**
* 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',
]);
});
}
This will restrict access to Telescope to only the users whose email addresses are included in the array.
Alternatively, you can override the authorization()
method in Laravel\Telescope\TelescopeApplicationServiceProvider
within your App\Providers\TelescopeServiceProvider
.
Note: Be cautious when making changes to the authorization methods, as it can compromise the security of your Telescope installation.
/**
* 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()]);
});
}
By changing the app()->environment()
condition to include your desired environment, you can allow access to Telescope in specific non-local environments.
For API applications, you can use cookie-based authentication. Add the secretTelescope
cookie secret and run the following code:
Gate::define('viewTelescope', function (?User $user) {
return array_key_exists('secretTelescope', $_COOKIE);
);
Remember to set the TELESCOPE_ENABLED
environment variable to true
and ensure that the APP_ENV
is set to local
or your desired environment.
These modifications should allow you to control access to the Laravel Telescope dashboard in various environments based on your specific requirements.