spatie/laravel-or-abort
Adds an OrAbort trait to Laravel models to abort with a chosen HTTP status when common calls fail (e.g., findOrAbort($id, 500) instead of returning null/false). Note: this package is no longer maintained.
findOrFail).abort()), reducing boilerplate for error handling.404, 500).findOrFail(), firstOrFail(), etc., making this package a thin wrapper. Limited value-add for most use cases.false/null conditions), not broader validation or error-handling needs.abort() or Eloquent methods).abort() behavior changes in Laravel).findOrFail) or a modern package (e.g., spatie/laravel-response for advanced responses).findOrFail, firstOrFail)? What specific use case does this package solve that natives don’t?null returns with HTTP errors (e.g., 404 for missing resources).find() without OrFail variants.if (!$model) abort(404); or find() without OrFail.abort().find() → findOrAbort()) incrementally.ResourceController).abort() method or Eloquent conventions.abort() signature changes).phpunit and static analysis (e.g., psalm).find() + abort() patterns with findOrAbort().where()->firstOrAbort()).spatie/laravel-response).abort() or Eloquent changes that may affect the package.| Failure Scenario | Impact | Mitigation |
|---|---|---|
Laravel version upgrade breaks abort() |
Aborts fail silently or throw errors | Test thoroughly; fallback to native findOrFail. |
| PHP 8.1+ incompatibility | Runtime errors or undefined behavior | Use a polyfill or fork the package. |
Custom middleware overrides abort() |
Unexpected responses | Test with middleware; isolate usage. |
| Missing resource triggers wrong HTTP code | Poor API/UX | Validate response codes in tests. |
findOrFail) as the preferred long-term solution.laravel-or-abort usage in PRs.How can I help you explore Laravel packages today?