Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Ignition Laravel Package

spatie/laravel-ignition

Beautiful, customizable error page for Laravel 10+ apps (PHP 8.1+). Shows detailed exception screens, offers helpful solutions, and can share errors to Flare. With a Flare API key, it tracks production errors and sends notifications.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require spatie/laravel-ignition
    

    Ignition is automatically registered via Laravel's service provider discovery.

  2. First Use Case: Trigger an error in your Laravel app (e.g., 1/0 in a route or controller). Ignition will replace the default Laravel error page with a rich, interactive error page featuring:

    • Stack traces with collapsible sections.
    • Solutions for common errors (e.g., missing imports, undefined variables).
    • Copy-to-clipboard functionality for stack traces.
    • Context tabs (Request, Response, Environment, etc.).
  3. Where to Look First:

    • Error Page: Inspect the rendered error page for solutions and context.
    • Configuration: Publish the config file:
      php artisan vendor:publish --provider="Spatie\Ignition\IgnitionServiceProvider" --tag="ignition-config"
      
      Edit config/ignition.php to customize behavior (e.g., disable solutions, adjust logging).
    • Flare Integration: Configure flare.php for error tracking in production (see Flare docs).

Implementation Patterns

Daily Workflows

  1. Local Development:

    • Debugging: Ignition’s interactive UI speeds up debugging by highlighting:
      • Missing imports (e.g., use App\Models\User; not found).
      • Undefined variables/methods with suggested fixes.
      • Database query errors with SQL context.
    • Copy-Paste: Use the "Copy" button to share stack traces with teammates.
    • Context Tabs: Switch between Request, Response, Environment, and Logs to diagnose issues holistically.
  2. Error Handling:

    • Custom Exceptions: Extend Ignition’s solutions for your app-specific errors. Override the Spatie\Ignition\Solutions\Solution class or register custom solutions in ignition.php:
      'solutions' => [
          \App\Solutions\MyCustomSolution::class,
      ],
      
    • Middleware Integration: Ignition automatically captures exceptions thrown in middleware. For custom middleware, ensure it doesn’t swallow exceptions:
      public function handle($request, Closure $next) {
          try {
              return $next($request);
          } catch (\Throwable $e) {
              // Let Ignition handle it
              throw $e;
          }
      }
      
  3. Production Monitoring:

    • Flare Integration: Configure flare.php with your API key to track errors in production:
      'key' => env('FLARE_API_KEY'),
      'project_id' => env('FLARE_PROJECT_ID'),
      
    • Error Notifications: Use Flare’s webhooks to notify Slack/email on critical errors.
    • Ignored Exceptions: Exclude non-critical errors (e.g., 404s) in ignition.php:
      'ignore_exceptions' => [
          \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
      ],
      
  4. Testing:

    • Assertions: Use Ignition’s assert helpers in tests to verify error pages:
      $response = $this->get('/error-route');
      $response->assertSee('Ignition Error Page');
      
    • Mocking: Disable Ignition in tests via config or middleware:
      $this->app->singleton(Ignition::class, function () {
          return Ignition::fake();
      });
      
  5. Performance:

    • Exclude Routes: Disable Ignition for API routes or performance-critical paths:
      Route::middleware(['ignition:off'])->group(function () {
          // Ignition disabled here
      });
      
    • Queue Reports: For high-traffic apps, queue Flare reports to avoid blocking:
      'queue_reports' => env('QUEUE_REPORTS', false),
      

Integration Tips

  1. Livewire/Alpine:

    • Ignition supports Livewire 3/4 and Alpine.js errors. The error page will show component-specific context (e.g., props, slots).
  2. Octane:

    • Works seamlessly with Laravel Octane. Ensure QUEUE_REPORTS is enabled to avoid blocking Swoole workers.
  3. Custom Views:

    • Override Ignition’s Blade views by publishing assets:
      php artisan vendor:publish --provider="Spatie\Ignition\IgnitionServiceProvider" --tag="ignition-views"
      
    • Extend resources/views/vendor/ignition/ to modify the error page layout.
  4. Logging:

    • Ignition logs errors to laravel.log by default. Customize log channels in ignition.php:
      'log' => 'single',
      'log_level' => 'debug',
      
  5. Security:

    • Sensitive Data: Ignition automatically redacts sensitive data (e.g., passwords, API keys) in context tabs. Add custom headers to redact:
      'ignored_headers' => [
          'x-api-key',
          'authorization',
      ],
      
    • Production: Disable solutions in production to avoid leaking sensitive info:
      'show_solutions' => env('APP_ENV') !== 'production',
      

Gotchas and Tips

Pitfalls

  1. Double Logging:

    • Issue: View data (e.g., Blade templates) may leak into laravel.log due to HTML dumping in context().
    • Fix: Updated in v1.7.1/v2.12.0. Ensure you’re on the latest version. If not, manually move HTML dumping to the Flare middleware.
  2. Middleware Order:

    • Issue: Some middleware (e.g., TrimStrings, ConvertEmptyStringsToNull) may not execute if placed after Ignition’s middleware.
    • Fix: Place Ignition’s middleware (Spatie\Ignition\Middleware\Ignition) last in your $middleware stack:
      protected $middleware = [
          // Other middleware...
          \Spatie\Ignition\Middleware\Ignition::class,
      ];
      
  3. Flare Reporting:

    • Issue: Reports from queues (e.g., jobs) may not send immediately.
    • Fix: Use queue_reports: true in ignition.php or manually trigger:
      \Spatie\Ignition\Facades\Ignition::report($exception);
      
  4. Livewire/Octane Conflicts:

    • Issue: Livewire 3/4 or Octane may interfere with Ignition’s error handling.
    • Fix: Ensure compatibility by updating Ignition (v2.6.0+ for Livewire 3, v2.5.2+ for Octane).
  5. Custom Exception Handling:

    • Issue: Custom exception handlers may override Ignition’s behavior.
    • Fix: Extend Laravel’s exception handler instead of replacing it:
      public function render($request, \Throwable $exception) {
          if (app()->bound('ignition') && $exception instanceof \Throwable) {
              return app('ignition')->render($request, $exception);
          }
          return parent::render($request, $exception);
      }
      

Debugging Tips

  1. Disable Ignition:

    • Temporarily disable Ignition in AppServiceProvider:
      public function boot() {
          if (app()->environment('local')) {
              \Spatie\Ignition\Ignition::fake();
          }
      }
      
  2. Inspect Context:

    • Use php artisan tinker to inspect Ignition’s context:
      $context = \Spatie\Ignition\Facades\Ignition::context();
      dd($context->all());
      
  3. Clear Cache:

    • If Ignition behaves unexpectedly, clear Laravel’s cache:
      php artisan cache:clear
      php artisan view:clear
      
  4. Check for Conflicts:

    • Disable other error handlers (e.g., Whoops, Debugbar) to isolate issues.

Extension Points

  1. Custom Solutions:

    • Create a solution for your app’s common errors:
      namespace App\Solutions;
      
      use Spatie\Ignition\Solutions\Solution;
      
      class UndefinedModelSolution extends Solution
      {
          public function solve($exception)
          {
              return 'Did you forget to define the `App\Models\'.classBasename($exception->model).'` model?';
          }
      
          public function matches($exception)
          {
              return $exception instanceof \ErrorException
                  && str_contains($exception->getMessage(), 'Undefined class');
          }
      }
      
    • Register it in ignition.php:
      'solutions' => [
          \App\Solutions\UndefinedModelSolution::class,
      ],
      
  2. Custom Context:

    • Add app-specific context to errors:
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony