sinemacula / laravel-repositories
Provides the repository data pattern to Laravel applications
Package info
github.com/sinemacula/laravel-repositories
pkg:composer/sinemacula/laravel-repositories
Requires
- php: ^8.3
- illuminate/database: *
- illuminate/support: *
Requires (Dev)
- brianium/paratest: ^7.8
- friendsofphp/php-cs-fixer: ^3.85
- orchestra/testbench: ^9.0 || ^10.0
- phpstan/extension-installer: ^1.4
- phpstan/phpdoc-parser: ^2.2
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5.3
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.13
This package is auto-updated.
Last update: 2026-03-07 02:54:33 UTC
README
This Laravel package provides a streamlined repository pattern layer for Eloquent models with criteria-driven query composition. It keeps the parts of l5-repository that are most useful in modern Laravel applications while removing unnecessary abstraction and maintenance overhead.
A big thanks to the creators of andersao/l5-repository for the original foundation this package builds on.
Features
- Repository Base Class: A container-resolved repository abstraction with explicit model validation, lifecycle reset
behavior, and a
boot()extension point for subclass initialization. - Criteria Lifecycle Controls: Persistent and one-shot criteria pipelines with runtime enable, disable, skip, and reset controls.
- Supplementary Capability Contracts: Opt-in interfaces that criteria can implement to declare eager-loading
(
DeclaresEagerLoading), field selection (DeclaresFieldSelection), relationship counts (DeclaresRelationshipCounts), and metadata (ContributesMetadata) alongside query modification. The repository collects these declarations at criteria application time and exposes them via dedicated accessors. - Scoped Query Mutation: Per-query scope registration for concise query customization without polluting models.
- Model-Like Ergonomics: Explicit query entrypoints (
query()/newQuery()) plus magic forwarding for model-style usage such asRepository::find($id).
Installation
To install the Laravel API Repositories package, run the following command in your project directory:
composer require sinemacula/laravel-repositories
Usage
// Explicit query entrypoint $users = $userRepository->query()->where('active', true)->get(); // Magic forwarding remains available for model-like usage $user = UserRepository::find($id);
Container Lifecycle
Repositories carry transient criteria and scope state while a query pipeline is being built. Register repositories as
transient or scoped bindings (bind or scoped) rather than singleton to avoid state leakage across requests.
Testing
composer test
composer test-coverage
composer check
Versioning Policy
This project adheres to Semantic Versioning.
What constitutes a breaking change:
- Adding, removing, or changing method signatures on any interface (
CriteriaInterface,RepositoryInterface,RepositoryCriteriaInterface,ContributesMetadata,DeclaresEagerLoading,DeclaresFieldSelection,DeclaresRelationshipCounts) - Changing the observable behavior of public methods in ways that violate documented contracts
- Changing protected members that are classified as stable extension points
Deprecation policy:
- Features planned for removal will be marked with
@deprecatedannotations that include a description, the recommended replacement, and the version in which the feature will be removed. - Deprecated features will survive at least one minor or major release cycle before removal.
- PHPStan (with
phpstan-deprecation-rules) will surface deprecation warnings in your IDE and CI pipeline.
What is NOT covered by stability guarantees:
- Members marked
@internal(including theManagesCriteriatrait) - Protected properties and methods not classified as stable extension points
- Undocumented behavioral details (e.g., internal criteria application ordering)
See CHANGELOG.md for a history of changes, UPGRADING.md for migration guidance between major versions, and EXTENSION-POINTS.md for the extension point classification and lifecycle documentation.
Contributing
Contributions are welcome via GitHub pull requests.
Security
If you discover a security issue, please contact Sine Macula directly rather than opening a public issue.
License
Licensed under the Apache License, Version 2.0.