sinemacula/laravel-repositories
Laravel repositories package offering a structured repository pattern layer for cleaner, testable data access. It helps organize queries behind interfaces, keeping your models and controllers lean.
composer require sinemacula/laravel-repositories:^3.2. v3.2.0 is an additive feature release: no breaking changes or deprecations are called out in the release notes.Attributes namespace.namespace App\Repositories;
use App\Models\User;
use SineMacula\LaravelRepositories\Attributes\Model;
use SineMacula\LaravelRepositories\Repository;
#[Model(User::class)]
final class UserRepository extends Repository
{
}
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
UserRepositoryInterface into a controller or action and replace ad-hoc Eloquent queries for that aggregate. The new v3.2.0 attribute is the cleanest way to tell the repository which model it manages, without overriding a $model property or model() method.UserRepositoryInterface, not UserRepository, in controllers/actions. Bind the concrete implementation in AppServiceProvider or a dedicated repository service provider.UserRepository with domain methods such as activeUsers(), findByEmail(), or paginateForAdmin() is more useful than a generic all/find/create/update/delete wrapper.DB::transaction().RefreshDatabase and a real repository for integration tests. The attribute makes it easier to instantiate a repository against the correct model in tests.$model property or model() override. Repeat incrementally rather than changing every repository at once.Model class. If the names collide, alias the attribute import.app(UserRepository::class)) and inspect the model it resolves. If the package exposes a getModel()-style method, use it in tinker to confirm the attribute is being read.How can I help you explore Laravel packages today?