Laravel Telescope is a powerful debugging and monitoring tool built by the Laravel team. It provides detailed insights into your application’s requests, exceptions, database queries, jobs, mail, notifications, cache, and more—all in an elegant dashboard.
๐ What is Laravel Telescope?
Laravel Telescope acts as a “developer’s black box,” recording everything that happens within your Laravel app. It’s especially useful during development and staging to track performance issues, failed jobs, or unexpected behavior.
๐งฉ Step 1: Install Telescope
Run the following Composer command in your Laravel project directory:
composer require laravel/telescope --dev
The --dev
flag ensures Telescope is only installed in your local development environment.
⚙️ Step 2: Publish Telescope Assets
Once the package is installed, publish the Telescope service provider and assets:
php artisan telescope:install
Then run your database migrations to create the necessary tables:
php artisan migrate
๐ Step 3: Protect Telescope in Production
By default, Telescope should not be accessible in production for security reasons. Laravel provides an environment-based check in app/Providers/TelescopeServiceProvider.php
:
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'admin@example.com',
]);
});
}
This ensures that only authorized users can view Telescope data if you ever enable it in production.
๐ Step 4: Access the Telescope Dashboard
Start your local development server:
php artisan serve
Then open Telescope in your browser at:
http://localhost:8000/telescope
You’ll see an elegant dashboard with tabs like Requests, Queries, Exceptions, Logs, Mail, and more.
๐ง Step 5: Exploring Telescope Features
- Requests: View incoming HTTP requests and responses.
- Exceptions: Track all errors and exceptions with full stack traces.
- Queries: Monitor SQL queries and execution times.
- Jobs & Queues: Debug queued jobs, failed jobs, and events.
- Cache: Inspect cache hits and misses.
- Mail & Notifications: View emails and notifications sent by your app.
- Logs: Centralized log entries for easy debugging.
๐ก Step 6: Managing Telescope Data
Telescope stores data in your database. To prevent it from growing too large, you can prune old entries:
php artisan telescope:prune --hours=48
You can even schedule pruning automatically by adding this to your app/Console/Kernel.php
:
protected function schedule(Schedule $schedule)
{
$schedule->command('telescope:prune --hours=48')->daily();
}
๐ฏ Conclusion
Laravel Telescope is an essential tool for any Laravel developer. Whether you’re debugging complex queries, tracking failed jobs, or optimizing performance, Telescope gives you the visibility you need to build better, more stable applications.
Start using it today, and take control of your Laravel app’s inner workings with ease!
Written by Rana Saha — Software Developer & Technical Blogger.
Comments
Post a Comment