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/123).Debugging Collaboratively:
Error Sharing in Development:
App\Exceptions\Handler) and appends a "Share" button to the error view (resources/views/errors/500.blade.php or similar).php artisan vendor:publish --tag=error-share-views
Modify resources/views/vendor/error-share/share-button.blade.php to adjust styling or add context (e.g., project name).Integration with Flare:
Programmatic Sharing:
shareError helper:
use Spatie\ErrorShare\ErrorShare;
try {
// Risky code...
} catch (\Exception $e) {
$shareUrl = ErrorShare::share($e);
// Log $shareUrl or send via email/Slack.
}
Environment-Specific Control:
.env:
ERROR_SHARE_ENABLED=false
local only) via config:
'enabled' => env('ERROR_SHARE_ENABLED', app()->environment('local')),
Custom Error Data:
ErrorShare facade:
$shareUrl = ErrorShare::share($e)
->withData(['user_id' => auth()->id(), 'custom_tag' => 'api-integration']);
API Endpoint for Remote Sharing:
Route::post('/api/errors/share', function (Request $request) {
$errorData = base64_decode($request->input('error_data'));
// Process or log $errorData.
});
Testing:
ErrorShare facade in tests to verify error handling:
$this->partialMock(Spatie\ErrorShare\ErrorShare::class, function ($mock) {
$mock->shouldReceive('share')->andReturn('http://test-url');
});
View Compilation Issues:
php artisan view:clear or publish views explicitly:
php artisan vendor:publish --tag=error-share-views
Flare Dependency:
shareError helper programmatically to generate a payload for custom processing.Environment Mismatches:
APP_URL=http://localhost), which are useless to teammates.ErrorShare config to exclude sensitive data:
'exclude_data' => ['request.headers', 'server.*'],
CSRF Token Errors:
@csrf
<x-error-share::share-button :exclude-csrf="true" />
Inspect the Payload:
error_data parameter to verify shared content:
echo $(echo "http://example.com/errors/123" | grep -oP '(?<=error_data=).+') | base64 --decode | jq
Log Shared Errors:
ErrorShare service to log URLs:
Spatie\ErrorShare\ErrorShare::macro('share', function ($exception) {
$url = parent::share($exception);
\Log::info("Error shared: $url", ['exception' => $exception]);
return $url;
});
Test Locally:
php artisan tinker to test sharing programmatically:
try { 1/0; } catch (\Exception $e) {
echo \Spatie\ErrorShare\ErrorShare::share($e);
}
Custom Share Endpoint:
$this->app->bind(\Spatie\ErrorShare\Contracts\ErrorSharer::class, function () {
return new CustomErrorSharer();
});
Add Metadata:
Error model used by the package to include project-specific fields:
namespace Spatie\ErrorShare;
class Error extends \Spatie\ErrorShare\Error {
public function getProjectName(): string {
return config('app.project_name', 'My App');
}
}
Localization:
php artisan vendor:publish --tag=error-share-lang
Then override in resources/lang/en/error-share.php:
return [
'share_button' => 'Send to Team',
];
Security:
Route::middleware(['auth'])->group(function () {
// Share routes...
});
How can I help you explore Laravel packages today?