L5 Repository

Repository and criteria pattern abstraction over Eloquent for Laravel applications

Library
Composer
v4.0.0
4,198stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
82/100Excellent
Development Activity52
Maintenance84
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture76
Code Quality74
Innovation62
Learning Curve66

L5 Repository (Packagist name prettus/l5-repository) implements the Repository and Criteria design patterns on top of Laravel’s Eloquent ORM, giving applications a data-access layer that sits between controllers and models. Instead of calling Eloquent directly from controllers, application code depends on generated Repository classes that implement a common RepositoryInterface, making query logic reusable, testable, and swappable independent of the underlying ORM calls.

The package adds a Criteria system for composing reusable query filters, a RequestCriteria implementation that automatically applies filtering/sorting/searching based on incoming HTTP request parameters, optional response caching keyed to repository calls, and Artisan generator commands that scaffold repositories, criteria, presenters, and validators. It has been a long-standing choice for Laravel teams that want an explicit repository layer without hand-rolling the boilerplate themselves.

What You Get

  • Artisan generators that scaffold repository, criteria, presenter, transformer, and validator classes for a given model
  • A RepositoryInterface/CriteriaInterface contract layer that decouples controllers from concrete Eloquent query calls
  • RequestCriteria, which automatically applies search, filter, and sort parameters from the incoming HTTP request to a repository query
  • Built-in repository-level response caching via a CacheableInterface/CacheableRepository trait
  • Optional presenter/transformer integration (via Fractal) for shaping repository output before it reaches the response layer

Common Use Cases

  • Introducing an explicit repository layer between controllers and Eloquent models in a Laravel API or application
  • Building reusable, composable query filters (Criteria) shared across multiple endpoints that need similar sorting/filtering behavior
  • Auto-applying request-driven search, filter, and sort parameters to index endpoints via RequestCriteria
  • Adding a caching layer around repeated repository queries without hand-writing cache-key logic per query

Under The Hood

Architecture The package is namespaced under Prettus\Repository, with src/Prettus/Repository/Eloquent/BaseRepository.php providing the concrete Eloquent-backed implementation of Contracts/RepositoryInterface.php that application repositories extend. Query composition happens through Criteria/ classes implementing CriteriaInterface, which repositories apply via a pushCriteria/getByCriteria mechanism; RequestCriteria (also under Criteria/) inspects the current HTTP request and builds search/filter/sort criteria automatically. Traits/CacheableRepository wraps repository method calls with cache-key generation and TTL handling defined in the package’s published config, while Generators/ implements the Artisan make:repository/make:criteria/etc. commands using Laravel’s code-generation stubs. Providers/RepositoryServiceProvider.php wires config publishing and generator command registration into the host Laravel application. Tech Stack Requires PHP 8.2+ and supports Laravel 8 through 13 (illuminate/http, and related Illuminate contracts), with optional integration against Fractal-style presenters/transformers for output shaping; no other heavyweight runtime dependencies beyond Laravel itself. Code Quality The test suite (BaseRepositoryIntegrationTest, CacheableRepositoryUnitTest, CacheableRepositoryRoundTripTest, RequestCriteriaIntegrationTest, RepositoryServiceProviderTest) mixes unit and integration-style tests with dedicated tests/Fixtures repository/model classes, indicating caching and request-criteria behavior are both exercised directly rather than only through manual QA. API Design The generator-driven workflow (artisan make:repository) and interface-first design keep day-to-day usage close to plain Eloquent calls ($repository->all(), $repository->find($id)), but the Criteria composition API and cache configuration require reading the package’s fairly long README to use beyond the basics.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search