Local development and debugging solution: Larravel Telescope


brief introduction

Laravel Telescope is an elegant debugging assistant specially designed for Laravel framework. Telescope can provide insight details for all operations such as requests, exceptions, logs, database queries, queue tasks, emails, notifications, cache operations, scheduling tasks, variable printing and so on that enter the application. Therefore, it will become another excellent partner of your local Laravel development environment.

install

Note: Telescope requires Laravel 5.7.7+version. You can php artisan --version View your own version of Larravel.

You can use Composer to install Telescope to the Laravel project:

 composer require laravel/telescope

After installation, use the Artisan command telescope:install Publish its public resources, and then run migrate Command to execute database changes:

 php artisan telescope:install php artisan migrate

Update Telescope

When updating Telescope, you need to republish public resources:

 php artisan telescope:publish

Only install in the specified environment

If you plan to install Telescope only in the local development environment, you can use it during installation --dev Tag:

 composer require laravel/telescope --dev

After the installation is complete, you need to start from the app Remove from configuration file TelescopeServiceProvider Registration of service providers. Instead, manually AppServiceProvider Of register Method:

 /** * Register any application services. * * @return void */ public function register() { if ($this->app->isLocal()) { $this->app->register(TelescopeServiceProvider::class); } }

to configure

After publishing the public resources of Telescope, its configuration file is located in config/telescope.php This configuration file allows you to configure listening options watchers Each configuration item contains a description of its purpose, so it is recommended that you read this configuration file through before using Telescope.

If necessary, you can completely disable the data collection function of Telescope enabled To set:

 'enabled' => env('TELESCOPE_ENABLED', true),

Data cleaning

If not cleaned, telescope_entries The table will quickly accumulate records. To alleviate this situation, you need to run Artisan commands every day by scheduling tasks telescope:prune To clean up old data:

 $schedule->command('telescope:prune')->daily();

By default, all data 24 hours ago will be cleared. You can use the hours Option to determine how long to save Telescope data. For example, the following command will delete all data created 48 hours ago:

 $schedule->command('telescope:prune --hours=48')->daily();

Background authorization

Telescope can be accessed through /telescope Background access. Like Horizon, by default, you can only use the local development environment( local )Access under. In your app/Providers/TelescopeServiceProvider.php In the file, there is a gate Method. Through this access control method, you can configure which users can access the Telescope background in a non local environment. You can modify this method at any time as needed to limit access to the 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, [ ' taylor@laravel.com ', ]); }); }

give the thumbs-up Cancel Like Collection Cancel Collection

<<Previous: Third party login solution: Laravel Socialite

>>Next: There is no next article