spatie/laravel-error-share
Adds a “Share” button to Laravel’s local error pages so you can generate a link and send the full exception details to a colleague for quick debugging help. Dev-only install via Composer; no setup needed.
Installation:
composer require spatie/laravel-error-share
Publish the config file (optional, but recommended for customization):
php artisan vendor:publish --provider="Spatie\ErrorShare\ErrorShareServiceProvider"
First Use Case:
Trigger an error in your Laravel app (e.g., 1/0 in a route or controller) and visit the generated error share URL. The package automatically generates a unique shareable link (e.g., http://your-app.test/share/errors/abc123) for each error.
Where to Look First:
config/error-share.php (for customization like base URL, expiration, or Flare integration).Spatie\ErrorShare\ShareErrorMiddleware (handles error sharing logic).php artisan error-share:share (manual sharing for non-HTTP errors).Automatic Sharing:
app/Http/Kernel.php under $middleware (for global sharing) or $routeMiddleware (for specific routes):
'share-error' => \Spatie\ErrorShare\ShareErrorMiddleware::class,
Route::get('/debug', function () {
throw new \Exception('Test error');
})->middleware('share-error');
Manual Sharing:
php artisan error-share:share --error="[object] (Exception(code: 0): Test error at ...)"
use Spatie\ErrorShare\ErrorShare;
ErrorShare::share(new \Exception('Manual error'));
Flare Integration:
flare_api_key in config/error-share.php to auto-upload errors to Laravel Flare.Customizing the Share URL:
Spatie\ErrorShare\ErrorShareUrlGenerator contract:
$app->bind(\Spatie\ErrorShare\ErrorShareUrlGenerator::class, function ($app) {
return new CustomUrlGenerator();
});
Error Metadata:
ErrorShare::share(new \Exception('Error'), [
'user_id' => auth()->id(),
'context' => ['key' => 'value'],
]);
Middleware Placement:
ShareErrorMiddleware after ConvertEmptyToNullMiddleware and ConvertEmptyToNullMiddleware in $middleware to ensure errors are captured correctly. Misplacement may result in silent failures or duplicate errors.Flare API Key:
flare_api_key is set but Flare is unreachable, errors will still be stored locally but won’t sync. Check storage/logs/laravel-error-share.log for sync failures.Error Expiration:
error_expiration_in_minutes (default: 1440 minutes/24 hours). Use php artisan error-share:prune to clean up old errors manually.Sensitive Data:
app.debug or custom error handlers to filter data before sharing:
ErrorShare::share($exception, [
'redact' => ['password', 'api_token'],
]);
Queue Workers:
error-share:prune command runs periodically (e.g., via Laravel Scheduler) to avoid storage bloat.Log Location:
storage/logs/laravel-error-share.log for sync errors or custom metadata issues.Testing Locally:
php artisan error-share:share to test error sharing without triggering HTTP errors:
php artisan error-share:share --error="[object] (Exception(code: 0): Test at ...)"
Custom Error Pages:
php artisan vendor:publish --tag="error-share-views"
resources/views/vendor/error-share/errors/show.blade.php.Environment-Specific Config:
ERROR_SHARE_FLARE_ENABLED=false in .env).Rate Limiting:
throttle to ShareErrorMiddleware if needed:
'share-error' => \Spatie\ErrorShare\ShareErrorMiddleware::class . '@' . __DIR__ . '/middleware/throttle',
Custom Error Storage:
Spatie\ErrorShare\ErrorShareRepository contract to store errors in a database or external service:
$app->bind(\Spatie\ErrorShare\ErrorShareRepository::class, function ($app) {
return new CustomErrorRepository();
});
Webhook Notifications:
error-shared events to send notifications (e.g., Slack, email):
Event::listen(\Spatie\ErrorShare\Events\ErrorShared::class, function ($event) {
// Send notification
});
Dynamic Error Metadata:
ErrorShare::share($exception, function () {
return ['user' => auth()->user()->name];
});
API Endpoint for Sharing:
Route::post('/api/errors/share', function (Request $request) {
$error = $request->input('error');
ErrorShare::share(new \Exception($error), $request->input('metadata', []));
return response()->json(['shared' => true]);
});
How can I help you explore Laravel packages today?