laravel/telescope
Laravel Telescope is a debug assistant for Laravel that provides a rich dashboard of requests, exceptions, logs, database queries, queued jobs, mail, notifications, cache activity, scheduled tasks, and more—ideal for local development and troubleshooting.
Installation:
composer require laravel/telescope --dev
Add to config/app.php under providers:
Laravel\Telescope\TelescopeServiceProvider::class,
And to aliases:
'Telescope' => Laravel\Telescope\TelescopeFacade::class,
Publish Configuration & Migrations:
php artisan telescope:install
This runs migrations and publishes config/assets.
Run Migrations:
php artisan migrate
Enable Telescope Middleware:
Add to routes/web.php (or routes/api.php for API routes):
Telescope::routes()->middleware('web');
Or for API-only:
Telescope::routes()->middleware('api');
Access Telescope:
Visit /telescope in your browser. Authenticate via Laravel’s default auth (or configure custom auth in config/telescope.php).
/telescope and click the latest Request entry.dd() or dump() outputs from your code.php artisan telescope:clearphp artisan telescope:prune (configurable in config/telescope.php).config/telescope.php:
'ignore_routes' => [
'telescope',
'horizon',
],
Middleware Integration: Add custom middleware to log specific data:
use Laravel\Telescope\IncomingRequest;
public function handle($request, Closure $next) {
IncomingRequest::createFromRequest($request)->store();
return $next($request);
}
Register in app/Http/Kernel.php:
protected $middleware = [
\App\Http\Middleware\LogRequestToTelescope::class,
];
Filtering Requests:
Exclude sensitive routes (e.g., API endpoints) in config/telescope.php:
'ignore_routes' => [
'api/*',
],
Slow Query Identification: Sort queries by execution time in Telescope’s Queries tab. Example SQL tuning:
// Before (N+1 problem)
$posts = Post::all();
foreach ($posts as $post) {
$post->comments; // Separate query per post
}
// After (Eager loading)
$posts = Post::with('comments')->get();
Binding Inspection: Click a query in Telescope to see raw bindings and adjust your Eloquent queries.
Telescope\Entry to log custom data:
use Laravel\Telescope\Entries\Entry;
class CustomExceptionEntry extends Entry
{
public function __construct($exception)
{
parent::__construct('exception', $exception);
$this->data['custom_field'] = $exception->getCustomData();
}
}
Register in AppServiceProvider:
public function boot()
{
Telescope::catchExceptions(function ($exception) {
return new CustomExceptionEntry($exception);
});
}
// In a job
try {
// Job logic
} catch (\Exception $e) {
throw $e; // Will appear in Telescope's "Jobs" tab
}
Filter failed jobs in Telescope’s UI or via:
Telescope::filter(function ($query) {
return $query->where('type', 'job')->where('is_failed', true);
});
Log Variables:
Use Telescope::dump($variable) anywhere in your code:
use Laravel\Telescope\Telescope;
public function someMethod()
{
$user = User::find(1);
Telescope::dump($user->posts); // Appears in "Dumps" tab
}
Conditional Dumping:
if (app()->environment('local')) {
Telescope::dump($sensitiveData);
}
phpunit.xml:
<env name="TELESCOPE_ENABLED" value="true"/>
Use in tests:
public function testSomething()
{
$this->withoutExceptionHandling();
// Test logic
$this->assertDatabaseHas('telescope_entries', [
'type' => 'request',
]);
}
Performance Overhead:
'enabled' => env('TELESCOPE_ENABLED', false),
telescope:prune to limit storage (default: 14 days).Sensitive Data Leaks:
Telescope::routes()->middleware(['web', 'auth']);
Telescope::macro('dump', function ($data) {
if (is_array($data) && isset($data['password'])) {
$data['password'] = '[REDACTED]';
}
return \Laravel\Telescope\Telescope::dump($data);
});
Database Bloat:
telescope_entries quickly. Adjust retention:
'prune' => [
'after' => '14 days',
'retention' => '1 year',
],
Asset Compilation Issues:
npm run dev
npm run build
vite.config.js includes Telescope assets:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js', 'resources/js/telescope.js'],
}),
],
});
Missing Entries:
TelescopeServiceProvider is registered and migrations ran.config/telescope.php for ignore_routes or ignore_exceptions.Query Log Not Showing:
DB::enableQueryLog() is not disabled globally.php artisan telescope:clear
Authentication Issues:
auth middleware. For custom auth:
Telescope::auth(function ($request) {
return $request->user()->isAdmin();
});
Job Tracking Gaps:
TelescopeServiceProvider is loaded before queue workers.config/horizon.php:
'middleware' => ['web', 'auth'],
Custom Entry Types:
Extend Laravel\Telescope\Entries\Entry to log application-specific events:
class PaymentEntry extends Entry
{
public function __construct($payment)
{
parent::__construct('payment', $payment);
$this->data['amount'] = $payment->amount;
$this->data['status'] = $payment->status;
}
}
Register in AppServiceProvider:
public function boot()
{
Telescope::macro('logPayment', function ($payment) {
return new PaymentEntry($payment);
});
}
Override Serialization: Customize how objects are serialized for dumps:
Telescope::macro('
How can I help you explore Laravel packages today?