Telescope


Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.


Official Documentation Link: https://laravel.com/docs/telescope

1. Installation

composer require laravel/telescope
php artisan telescope:install
php artisan migrate

2. Authorization

  • Within your config/telescope.php file, add in the auth middleware that you would like to use for the authorization.
  • For example, adding 'auth:admin' will use the laravel default authentication middleware with the 'admin' guard for the authorization on Telescope.
'middleware' => [
    'web',
    'auth:admin',
    Authorize::class,
],
  • Within your app/Providers/TelescopeServiceProvider.php file, there is an authorization gate definition.
  • This authorization gate controls access to Telescope in non-local environments.
  • You are free to modify this gate as needed to restrict access to your Telescope installation:


To restrict based on permission

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return ($user->can('operation.telescope'));
    });
}


To restrict based on email address

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'support@etctech.com.my'
        ]);
    });
}

3. Data Pruning

  • Without pruning, the telescope_entries table can accumulate records very quickly.
  • To mitigate this, you should schedule the telescope:prune Artisan command to run daily:
  • The following command will delete all records created over 48 hours ago:
$schedule->command('telescope:prune --hours=48')->daily();