Laravel Telescope for PHP: Complete Guide with Examples

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course
\n

Laravel Telescope: Elegant Debugger for PHP Applications

\n\n
\n

1. What is Laravel Telescope and why do you need it?

\n

Laravel Telescope is a powerful debugging and monitoring tool for Laravel applications, developed by the Laravel team. It provides developers with an "inspector's view" of what is happening inside the application: from incoming requests and SQL queries to queue jobs, exceptions, and logs. Telescope works as a dashboard that collects and displays all telemetry in real time.

\n

Why is this needed? In modern web development, applications are becoming increasingly complex: queues, caching, external APIs, complex SQL queries are used. Without a tool like Telescope, a developer has to manually add dd() or Log::debug() to the code, which slows down development and does not provide a complete picture. Telescope automatically collects data about each request, showing execution time, number of database queries, memory usage, and much more. This turns debugging from guesswork into an exact science.

\n

The key advantage of Telescope is its unobtrusiveness. It works "out of the box" and does not require changing the application code. Data is stored in a database (MySQL or SQLite by default), allowing you to analyze request history. Telescope is especially useful when developing APIs, working with queues, and debugging slow pages.

\n
\n\n
\n

2. Installation

\n

Installing Laravel Telescope is done via Composer, the standard package manager for PHP. Run the following command in the root of your Laravel project:

\n
composer require laravel/telescope --dev
\n

The --dev flag is important: Telescope is intended only for local development and should not be installed on production servers. After installing the package, you need to publish the assets (CSS/JS) and configuration:

\n
php artisan telescope:install
\n

This command will create the configuration file config/telescope.php and a database migration. Then run the migration to create tables for storing Telescope data:

\n
php artisan migrate
\n

After this, Telescope will be available at /telescope in your application. If you are using Laravel Sail (Docker), do not forget to restart the containers.

\n
\n\n
\n

3. Quick Start — Minimal Working Example

\n

After installation, Telescope automatically starts collecting data. You do not need to write any additional code. Simply open your browser and go to http://your-app.test/telescope.

\n

You will see a panel with tabs: Requests, Commands, Schedule, Jobs, Exceptions, Logs, Dumps, Queries, Models, Mail, Notifications, Cache, Events, Gates.

\n

To make sure everything is working, make a simple request to any route in your application. For example, open the home page. Then go to Telescope and select the Requests tab. You will see a record of your request with details: method, URI, status, duration, number of SQL queries, etc.

\n

Here is an example of how you can manually add data to Telescope for debugging:

\n
<?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse App\\Models\\User;\nuse Laravel\\Telescope\\Telescope;\n\nclass UserController extends Controller\n{\n    public function show($id)\n    {\n        // Te                    

Recommendations