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 Model Exists Rule Laravel Package

mvanduijker/laravel-model-exists-rule

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development: Enables robust validation for model existence in forms/APIs, reducing edge-case bugs (e.g., orphaned references, invalid IDs).
  • Roadmap Prioritization: Justifies investing in validation-heavy workflows (e.g., admin panels, user management, or complex CRUD operations) where data integrity is critical.
  • Build vs. Buy: Avoids reinventing custom validation logic for model checks, saving engineering time and reducing technical debt.
  • Use Cases:
    • Referential Integrity: Validate foreign keys (e.g., post_id in a Comment model must exist in Posts).
    • Soft Deletes: Check if a model exists and is not soft-deleted (via whereDoesntHave or whereNotNull).
    • Multi-Table Joins: Validate existence across related tables (e.g., a User must have an active Subscription).
    • APIs: Ensure request payloads reference valid resources (e.g., update_user_profile where user_id must exist).

When to Consider This Package

  • Adopt When:

    • Laravel’s built-in Rule::exists() is insufficient (e.g., needs joins, whereHas, or soft-delete checks).
    • Your app relies on complex validation (e.g., SaaS platforms, e-commerce, or multi-tenant systems).
    • You frequently validate model relationships (e.g., OrderCustomerAddress).
    • Engineering bandwidth is limited, and custom validation logic would introduce maintenance overhead.
  • Look Elsewhere If:

    • Your validation needs are simple (use Rule::exists() or Eloquent’s findOrFail).
    • You’re using a non-Laravel framework (this package is Laravel-specific).
    • You require real-time validation (e.g., GraphQL subscriptions) where this package’s synchronous approach is limiting.
    • Your team prefers writing custom validation logic for full control (e.g., highly optimized queries).

How to Pitch It (Stakeholders)

For Executives: "This package lets us validate that database records exist before processing user actions—like ensuring a user can’t delete a non-existent order or update a profile tied to an invalid customer. It’s a lightweight, battle-tested solution that reduces bugs in critical workflows, saving support costs and improving reliability. Think of it as a ‘guardrail’ for our data integrity, with minimal engineering lift."

For Engineering: *"This replaces ad-hoc try-catch blocks or manual Model::find() checks in validation logic with a clean, reusable rule. Key benefits:

  • Flexibility: Supports joins, whereHas, and soft deletes out of the box.
  • Performance: Uses Eloquent’s query builder efficiently (avoids N+1 queries).
  • Maintainability: Centralizes validation logic, making it easier to update rules app-wide.
  • Integration: Works seamlessly with Laravel’s Form Requests and API validation. Example: Instead of writing if (!$user = User::find($request->user_id)) { abort(404); }, we’ll use new ModelExists(User::class)—cleaner and more scalable."*
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle