spatie/laravel-error-share
Adds a “Share” button to Laravel exception pages so you can generate a link and let teammates view the full error details without screen sharing. Install as a dev dependency and share local exceptions instantly.
Installation:
composer require spatie/laravel-error-share --dev
Trigger an Error:
1/0 in a route or controller).Share the Error:
https://your-app.test/errors/12345).Debugging Collaboratively:
500 error on a checkout page.Error Occurrence:
render method for exceptions (via App\Exceptions\Handler).Shareable Link Generation:
// Manually trigger (e.g., in a test or CLI command)
\Spatie\ErrorShare\ErrorShare::share($exception);
Flare Integration:
Override the default Blade view (resources/views/vendor/error-share/share-button.blade.php) to:
<button class="custom-class" onclick="shareError('{{ $errorId }}')">
Debug This →
</button>
// In AppServiceProvider@boot()
if (app()->environment('production')) {
\Spatie\ErrorShare\ErrorShare::disable();
}
Share errors from CLI commands, queues, or tests:
use Spatie\ErrorShare\ErrorShare;
// In a command
public function handle()
{
try {
// Risky operation
} catch (\Exception $e) {
ErrorShare::share($e);
$this->info('Error shared: ' . ErrorShare::getShareUrl($e));
}
}
Add custom context to shared errors:
// In AppServiceProvider@boot()
\Spatie\ErrorShare\ErrorShare::extend(function ($exception, $payload) {
$payload['custom_data'] = [
'user_id' => auth()->id(),
'feature_flag' => config('flags.new_ui'),
];
});
Expose errors via an API (e.g., for mobile apps):
Route::get('/errors/{id}', function ($id) {
return \Spatie\ErrorShare\ErrorShare::getError($id);
})->middleware('auth');
Flare Dependency:
composer require spatie/laravel-flare-react --dev
Environment Variables:
APP_KEY) is automatically redacted in Flare, but ensure .env is never committed.php artisan config:clear after sharing if config changes.Caching Issues:
flare.error_share_expiration_minutes).config/flare.php.Laravel 12+ Quirks:
composer update spatie/laravel-error-share --dev.Queue Jobs:
ErrorShare::share() in the job’s failed() method or a retry listener.Check the Error ID:
/errors/abc123 must match Flare’s stored errors. If missing, the link 404s.php artisan flare:list to verify errors exist in Flare.Disable for Production:
// config/flare.php
'error_share' => [
'enabled' => env('APP_ENV') !== 'production',
],
Custom Error Pages:
resources/views/errors/500.blade.php), include the share button manually:
@if(config('flare.error_share.enabled'))
@include('vendor.error-share.share-button', ['errorId' => 'custom-id'])
@endif
Modify Payload:
Spatie\ErrorShare\ErrorShare::getPayload() to include/exclude data:
public static function getPayload(Exception $exception): array
{
$payload = parent::getPayload($exception);
unset($payload['context']['session']); // Remove session data
return $payload;
}
Custom Storage:
Spatie\ErrorShare\ErrorShareRepositoryInterface.Link Expiration:
// config/flare.php
'error_share_expiration_minutes' => 1440, // 24 hours
Local Testing:
// In a test
\Spatie\Flare\Flare::storeError($exception);
$url = \Spatie\ErrorShare\ErrorShare::share($exception);
$this->assertStringContainsString('errors/', $url);
// app/Providers/AppServiceProvider.php
public function boot()
{
if (app()->environment('production')) {
\Spatie\ErrorShare\ErrorShare::disable();
}
}
How can I help you explore Laravel packages today?