laravel/liferaft
Liferaft is a Laravel package that adds reliable background job and queue tooling, helping you run tasks safely with better control, monitoring, and recovery. Ideal for apps that need robust async processing and fewer failed or stuck jobs.
Installation:
composer require laravel/liferaft
Add the service provider to config/app.php under providers:
Laravel\Liferaft\LiferaftServiceProvider::class,
Publish Config:
php artisan vendor:publish --provider="LiferaftServiceProvider" --tag="liferaft-config"
This generates config/liferaft.php with default settings.
First Use Case:
Trigger a bug report from an exception handler (e.g., app/Exceptions/Handler.php):
use Laravel\Liferaft\Liferaft;
public function report(Throwable $exception)
{
Liferaft::report($exception);
// Parent report logic...
}
Reporting Exceptions:
try {
// Risky operation
} catch (Throwable $e) {
Liferaft::report($e, [
'user_id' => auth()->id(),
'context' => ['key' => 'value'],
]);
}
Manual Reports:
Liferaft::report(new \RuntimeException('Custom error'), [
'custom_data' => 'foo',
]);
Conditional Reporting:
if (app()->environment('production')) {
Liferaft::report($exception);
}
Middleware: Use Liferaft::report() in middleware to catch unhandled exceptions:
public function handle($request, Closure $next)
{
try {
return $next($request);
} catch (Throwable $e) {
Liferaft::report($e);
throw $e; // Re-throw for other handlers
}
}
Artisan Commands: Report errors from CLI commands:
try {
// Command logic
} catch (Throwable $e) {
Liferaft::report($e);
$this->error('Failed. Report sent.');
}
Queue Workers: Wrap queue jobs in try-catch blocks and report failures:
try {
$job->handle();
} catch (Throwable $e) {
Liferaft::report($e, ['job' => get_class($job)]);
throw $e;
}
Double Reporting:
Liferaft::report() isn’t called in both Handler.php and middleware for the same exception.exception->liferaft_reported) to avoid duplicates.Sensitive Data Leakage:
request->all() or session data to reports.Liferaft::report($e, [
'user_id' => auth()->id(),
'ip' => request()->ip(),
// Avoid: 'password' => request()->input('password'),
]);
Rate Limiting:
config/liferaft.php:
'rate_limit' => 5, // Max reports per minute
Environment-Specific Issues:
app()->environment('local') checks.Log Locally:
Enable local logging in config/liferaft.php:
'log_locally' => true,
Check storage/logs/liferaft.log for failed reports.
Verify Webhook:
Use php artisan liferaft:test to simulate a report and validate the webhook endpoint.
Custom Payloads: Override the payload structure via a service provider:
Liferaft::extend(function ($payload, $exception) {
$payload['custom_field'] = 'value';
return $payload;
});
Transport Layer:
Replace the default GitHub/GitLab reporter by binding a custom Liferaft\Reporter implementation:
$this->app->bind(Liferaft\Reporter::class, function () {
return new CustomReporter();
});
Event Listeners:
Listen for liferaft.reporting events to modify reports:
Liferaft::reporting(function ($report) {
$report->payload['extra'] = 'data';
});
How can I help you explore Laravel packages today?