spatie/ignition
Ignition is a beautiful, customizable error page for PHP apps. Register it to get rich exception screens with stack traces, context, and a polished UI with light and dark mode. Integrates via Laravel, Symfony, Drupal, and more.
Installation:
composer require spatie/ignition
For Laravel, use spatie/laravel-ignition instead.
Basic Registration:
Add this to your bootstrap file (e.g., bootstrap/app.php in Laravel):
use Spatie\Ignition\Ignition;
Ignition::make()->register();
First Use Case: Throw an exception in a route or controller:
throw new \Exception('Test error for Ignition');
Visit the URL in your browser to see the Ignition error page.
Error Handling: Ignition automatically captures uncaught exceptions and renders them in a user-friendly UI. No manual error handler setup is required.
Environment-Specific Behavior:
Ignition::make()
->shouldDisplayException(app()->environment('local'))
->register();
Integration with Laravel:
spatie/laravel-ignition. Use this package for Laravel projects.spatie/ignition package.Flare Integration: Send errors to Flare for monitoring in production:
Ignition::make()
->runningInProductionEnvironment(app()->environment('production'))
->sendToFlare(config('services.flare.key'))
->register();
Custom Solutions:
ProvidesSolution in custom exceptions:
class CustomException extends \Exception implements \Spatie\Ignition\Contracts\ProvidesSolution {
public function getSolution(): \Spatie\Ignition\Contracts\Solution {
return new class implements \Spatie\Ignition\Contracts\Solution {
public function getSolutionTitle(): string { return 'Fix the config'; }
public function getSolutionDescription(): string { return 'Update `config/app.php`'; }
public function getDocumentationLinks(): array { return []; }
};
}
}
Ignition::make()
->addSolutionProviders([
\App\Providers\CustomSolutionProvider::class,
])
->register();
AI-Powered Solutions:
Use OpenAI to suggest fixes (requires openai-php/client):
$aiProvider = new \Spatie\Ignition\Solutions\OpenAi\OpenAiSolutionProvider(config('services.openai.key'));
$aiProvider->applicationType('Laravel 10.x');
Ignition::make()
->addSolutionProviders([$aiProvider])
->register();
Flare Customization:
Ignition::make()
->configureFlare(function (\Spatie\FlareClient\Flare $flare) {
$flare->context('User', auth()->id());
$flare->registerMiddleware(\App\FlareMiddleware::class);
})
->register();
$flare->censorRequestBodyFields(['password', 'token']);
Theming: Switch between light/dark mode:
Ignition::make()->setTheme('dark')->register();
Production Leaks:
shouldDisplayException(false) in production:
Ignition::make()
->shouldDisplayException(false)
->runningInProductionEnvironment(true)
->sendToFlare(config('services.flare.key'))
->register();
Path Trimming:
applicationPath from stack traces by default. If stack traces appear broken, verify the path:
Ignition::make()->applicationPath(base_path())->register();
AI Solution Quirks:
$aiProvider->useCache(app('cache'), 3600); // Cache for 1 hour
Flare Configuration:
spatie/flare-client-php is installed for Flare features:
composer require spatie/flare-client-php
$flare->anonymizeIp();
Middleware Conflicts:
App\Exceptions\Handler) that might be swallowing exceptions. Ignition should be registered before other exception handlers.Disable Ignition Temporarily:
Comment out Ignition::make()->register() to test if another package is interfering with error handling.
Check for Overrides: If custom solutions aren’t showing, verify:
ProvidesSolution.Flare Not Receiving Errors:
config/services.php.runningInProductionEnvironment(true) is set.Performance Impact:
if (app()->environment('local')) {
Ignition::make()->addSolutionProviders([$aiProvider])->register();
}
Custom Error Pages: Override Ignition’s UI by publishing and modifying its assets:
composer require spatie/ignition-ui
php artisan vendor:publish --provider="Spatie\Ignition\IgnitionServiceProvider" --tag="ignition-assets"
Solution Providers: Create reusable providers for team-wide error patterns:
class DatabaseSolutionProvider implements \Spatie\Ignition\Contracts\HasSolutionsForThrowable {
public function canSolve(\Throwable $throwable): bool {
return str_contains($throwable->getMessage(), 'SQLSTATE[42S02]');
}
public function getSolutions(\Throwable $throwable): array {
return [new \Spatie\Ignition\Contracts\Solution {
// Solution logic...
}];
}
}
Flare Middleware: Extend Flare reports with custom logic (e.g., user sessions, logs):
class SessionMiddleware implements \Spatie\FlareClient\FlareMiddleware\FlareMiddleware {
public function handle(\Spatie\FlareClient\Report $report, \Closure $next) {
$report->context('Session', session()->all());
return $next($report);
}
}
Dark Mode Customization: Override CSS variables in the published assets to match your app’s theme:
:root {
--ignition-bg: #1a1a1a;
--ignition-text: #e0e0e0;
}
How can I help you explore Laravel packages today?