BaseRepository), enabling tailored behavior for specific use cases (e.g., caching, soft deletes, or multi-database support).BaseRepository) and a repository service provider, reducing manual setup.retrieved, saved), enabling observability and side effects.UserRepository) alongside existing Eloquent.Order, Invoice).UserRepositoryInterface) for gradual replacement.new EloquentBuilder in PHP 8.1).composer require littlebug/laravel-repository.php artisan vendor:publish --provider="Littlebug\Repository\RepositoryServiceProvider".config/app.php.BaseRepository for each model (e.g., UserRepository extends BaseRepository).findByEmail()).AppServiceProvider:
$this->app->bind(
'App\Repositories\UserRepository',
'Littlebug\Repository\BaseRepository'
);
User::find() with $userRepository->find().public function __construct(UserRepository $userRepository) { ... }
scopes) are made in one place.with() clauses).| Risk | Mitigation |
|---|---|
| Package abandonment | Fork the repo or maintain a private fork. |
| Laravel incompatibility | Test with Laravel 10+ in a staging environment. |
| Performance regressions | Benchmark against direct Eloquent usage. |
| Over-abstraction | Start small; avoid repositories for trivial queries. |
| Testing complexity | Use mock repositories in unit tests; integrate with Pest/Laravel Testcase. |
How can I help you explore Laravel packages today?