sinemacula/laravel-repositories

Provides the repository data pattern to Laravel applications

Installs: 14 424

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/sinemacula/laravel-repositories

v2.0.0 2026-02-21 05:45 UTC

README

Latest Stable Version Build Status Maintainability Code Coverage Total Downloads

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 and lifecycle reset behavior.
  • Criteria Lifecycle Controls: Persistent and one-shot criteria pipelines with runtime enable, disable, skip, and reset controls.
  • 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 as Repository::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

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.