Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Or Abort Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Legacy System Maintenance: Justify use in older Laravel projects (pre-5.3+) where native findOrFail() or firstOrFail() methods aren’t available or require customization (e.g., non-standard HTTP codes).
  • Consistency in Error Handling: Align error responses across legacy APIs where OrAbort was previously used as a convention (e.g., 404 for missing resources, 500 for validation failures).
  • Quick Wins for Tech Debt: Address deprecated or redundant custom findOrAbort implementations in the codebase with a single, maintained trait (even if archived, it’s a drop-in replacement).
  • Avoid Rebuilding: Skip reinventing a simple trait for edge cases (e.g., findOrAbort(422) for validation errors) when the package already exists.
  • Documentation/Onboarding: Use as a reference for junior devs to understand Laravel’s OrFail pattern in legacy contexts.

When to Consider This Package

  • Avoid if:

    • Using Laravel 5.3+: Native findOrFail(), firstOrFail(), or existsOrFail() methods are built-in and preferred.
    • Modern Alternatives Exist: Consider spatie/laravel-query-builder or Laravel’s own Illuminate\Database\Eloquent\Builder for advanced query logic.
    • Maintenance Risk: The package is archived (last release 2015) and lacks updates. Use only for critical legacy systems with no plans to migrate.
    • Custom Logic Needed: Require dynamic abort conditions (e.g., findOrAbortIf($condition, $code)), which this trait doesn’t support.
    • New Projects: Never use in greenfield development—opt for Laravel’s built-in solutions or modern packages.
  • Consider if:

    • Supporting a frozen Laravel version (e.g., 5.1–5.2) with no upgrade path.
    • Needing non-standard abort codes (e.g., 422 for validation) in legacy APIs.
    • Minimal refactoring budget exists to replace scattered findOrFail overrides.

How to Pitch It (Stakeholders)

For Executives: "This is a low-risk, high-impact fix for legacy systems where custom findOrAbort logic is duplicated across the codebase. By adopting this archived but battle-tested package, we standardize error handling (e.g., consistent 404/500 responses) without rewriting logic. It’s a one-time cleanup for systems we’re not actively modernizing, saving dev time while reducing technical debt. The MIT license and zero dependents mean no vendor lock-in."

For Engineering: *"This trait fills a gap in pre-5.3 Laravel where findOrFail didn’t exist or needed custom HTTP codes. It’s a drop-in replacement for ad-hoc try-catch blocks or manual abort() calls. Caveats:

  • Not maintained: Only use if you’re stuck on Laravel <5.3 or have no upgrade plans.
  • Limited scope: Only handles basic findOrAbort($id, $code)—don’t use for complex logic.
  • Deprecation note: Flag it for removal if/when the system upgrades.

Proposed action: Add to composer.json as a dev dependency, update legacy controllers to use the trait, and document its use as a temporary solution in the architecture docs."*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport