Weave 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

Doctrine Specification Laravel Package

rikbruil/doctrine-specification

A Doctrine specification-pattern package for composing reusable, testable query criteria. Combine specifications with and/or/not, apply them to repositories, and keep complex filtering logic out of entities and controllers. Supports modular filters and cleaner, more maintainable data access.

Deep Wiki
Context7

Product Decisions This Supports

  • Dynamic filtering and search features: Any roadmap item that requires user-driven query composition — admin dashboards, faceted search, advanced filter panels, saved searches, or report builders — maps directly onto composable Specification objects rather than ad-hoc query strings in controllers.
  • Build vs. buy for query logic: The package is a thin, MIT-licensed implementation of a well-known pattern (Eric Evans / Spring Data Specifications). It is cheap to adopt and cheap to replace, so the real build-vs-buy question is whether to standardize on an internal "criteria object" convention at all — this package is a credible starting reference implementation even if the code is ultimately vendored.
  • Segmentation and rule-based targeting: Specifications compose with and/or/not, which makes them a natural fit for audience segmentation, eligibility rules, entitlement checks, and "match any/all of these conditions" product logic — features that otherwise tend to accrete brittle conditional SQL.
  • Multi-tenant and permission-scoped data access: Mandatory scoping (tenant, role, visibility) can be modeled as a base Specification composed into every query, giving a single enforceable place to audit data-access rules — a compliance and security-relevant product decision, not just a code-style one.
  • Repository/domain boundary decisions: If the roadmap involves extracting a domain layer, modularizing a monolith, or reusing query logic across services and jobs, this supports the architectural bet that query intent should be expressed as objects owned by the domain rather than SQL buried in persistence code.
  • Testability investment: Specifications are plain objects, so filter behavior can be unit-tested and product rules asserted directly — reducing the cost of regression coverage for complex filter matrices, which is typically where filter features quietly break.
  • De-prioritized / not supported: This is not an Eloquent package and does not help products built entirely on Eloquent. It does not solve pagination, caching, indexing, or query-plan optimization — those remain separate product and engineering decisions.

When to Consider This Package

Consider adoption when most of the following hold:

  • The application uses Doctrine ORM/DBAL (directly, or via a Laravel-Doctrine bridge, or in a Symfony service alongside a Laravel front end). If the data layer is Eloquent, this package is not applicable and the pattern should be evaluated against Eloquent scopes and query builders instead.
  • Query criteria are genuinely dynamic and combinatorial — multiple optional filters, nested boolean logic, user-configurable conditions — rather than a handful of fixed where clauses that a scope or repository method already handles cleanly.
  • The same filtering logic must be reused across contexts: API endpoints, queued exports, scheduled jobs, admin tooling, and internal services. Reuse is where Specification composition pays for itself.
  • The team is comfortable with domain-driven design vocabulary and object-oriented modeling; the pattern adds indirection that only pays off when the team reads it fluently.
  • You want a thin, low-risk dependency with no framework lock-in: MIT license, no runtime services, and it can be wrapped behind an internal interface so the package can be swapped without touching call sites.

Look elsewhere or build in-house when:

  • Maturity and support risk outweigh the benefit. Roughly 50 stars and no visible vendor backing means the maintenance risk is real. For a small code surface this is often acceptable, but it should not become a load-bearing dependency in a business-critical path without an internal fork or wrapper.
  • The feature set is simple and stable — a few well-named repository methods are cheaper to read, review, and onboard than a specification hierarchy.
  • Query performance is the dominant concern. Composition can generate large SQL, redundant joins, and unexpected N+1-style explosions. Without an explicit review discipline and query logging, specification trees can degrade performance invisibly.
  • You need vendor SLAs, security patching guarantees, or long-term commercial support — this package cannot provide them.
  • The team is Laravel-native and Doctrine-unfamiliar; the learning cost of Doctrine plus the pattern together is rarely justified by one filtering feature.

How to Pitch It (Stakeholders)

For executives: We are evaluating a small, free (MIT) open-source component that standardizes how we build dynamic search and filtering. The business value is faster delivery of filter-heavy features — admin dashboards, saved searches, segmented audiences — with reusable rules instead of one-off code, which lowers long-term maintenance cost and reduces the risk of filter logic drifting between screens. The strategic risk is low: the library is small and replaceable, and the underlying pattern is an industry standard, so we are not locked in. The main trade-off is that it depends on our data-access approach (Doctrine) and on a small maintainer community, so we would wrap it behind our own interface rather than let it spread through the codebase. Recommendation: pilot on one filtering feature, measure delivery time and query performance, then decide on broader standardization.

For engineering: This implements the Specification pattern for Doctrine — criteria as small, composable, testable classes combined with and/or/not, instead of query construction scattered across controllers and repositories. Upside: query intent lives in the domain, mandatory scoping (tenant, permissions) becomes one composable unit, and filter behavior becomes unit-testable rather than only integration-tested. Downsides to plan for: the dependency is small and thinly maintained (~50 stars), so we should isolate it behind an internal SpecificationInterface or thin adapter to keep swap cost near zero; and composition can produce expensive SQL, so we need query-count and slow-query visibility in CI or staging before this becomes standard. It only applies if we are on Doctrine — if the service is Eloquent-only, we should adopt the pattern with a small internal implementation rather than the package.

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.
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk