PHPackages                             salehhashemi/laravel-repository - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. salehhashemi/laravel-repository

ActiveLibrary[Database &amp; ORM](/categories/database)

salehhashemi/laravel-repository
===============================

Implementing the repository pattern for Laravel projects.

v0.6.0(2w ago)2010.5k2MITPHPPHP ^8.2CI passing

Since Dec 6Pushed 2w ago3 watchersCompare

[ Source](https://github.com/salehhashemi1992/laravel-repository)[ Packagist](https://packagist.org/packages/salehhashemi/laravel-repository)[ Docs](https://github.com/salehhashemi1992/laravel-repository)[ RSS](/packages/salehhashemi-laravel-repository/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (10)Versions (13)Used By (0)

Laravel Repository Pattern
==========================

[](#laravel-repository-pattern)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f3fabd5ea4ab5e4133b5faadd11ccfaa72c2a53a00996bf8073e1d68a05a5af4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616c656868617368656d692f6c61726176656c2d7265706f7369746f72792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salehhashemi/laravel-repository)[![Total Downloads](https://camo.githubusercontent.com/06ed04a3165a9290333d3f8669775bee13b70c972b5f4a7e09405688896bf0e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616c656868617368656d692f6c61726176656c2d7265706f7369746f72792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salehhashemi/laravel-repository)[![GitHub Actions](https://camo.githubusercontent.com/9b687f9c2e1ee5d28559503b1a0144167e3e20d178988c3235722efe05f9acd1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616c656868617368656d69313939322f6c61726176656c2d7265706f7369746f72792f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d61696e266c6162656c3d7374617469632d616e616c79736973)](https://github.com/salehhashemi1992/laravel-repository/actions/workflows/static-analysis.yml)[![GitHub Actions](https://camo.githubusercontent.com/b3d85debc23b58b783880ffd2b5bc47b72f1af988b6d81e27075e79ae36a9fed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616c656868617368656d69313939322f6c61726176656c2d7265706f7369746f72792f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d72756e2d7465737473)](https://github.com/salehhashemi1992/laravel-repository/actions/workflows/run-tests.yml)[![codecov](https://camo.githubusercontent.com/568f9f8a0b90dff27f5c13ff1f6f74f11bdbc253390f22427325e91a5fc0ea6d/68747470733a2f2f636f6465636f762e696f2f67682f73616c656868617368656d69313939322f6c61726176656c2d7265706f7369746f72792f67726170682f62616467652e7376673f746f6b656e3d6e6969697a366c32744a)](https://codecov.io/gh/salehhashemi1992/laravel-repository)[![PHPStan](https://camo.githubusercontent.com/f60d96f7c2579690ab6dfa8918f777fe93a02a92301c661eb38a85861a92b780/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d627269676874677265656e2e7376673f7374796c653d666c6174)](https://phpstan.org/)

This Laravel package simplifies and streamlines data access by implementing the repository pattern. It provides a powerful abstraction layer for your database interactions, enhanced with flexible filtering, searching, and criteria-based querying.

[![Header Image](./assets/header.png)](./assets/header.png)

Features
--------

[](#features)

- **Repository Abstraction:** Decouples data access logic from application code.
- **Dynamic Filtering:** Apply filters to refine database queries.
- **Criteria-Based Filtering:** Define reusable criteria for common query constraints.
- **Search Functionality:** Implement custom search logic based on user input.
- **Modular Repository Interface:** Enforces consistency and maintainability.
- **Ease of Integration:** Seamlessly integrates with Laravel applications.
- **Development Tools:** Automate repository, interface, and filter creation with the `make:repository` command.

Installation
------------

[](#installation)

To install the package, you can run the following command:

```
composer require salehhashemi/laravel-repository
```

Compatibility
-------------

[](#compatibility)

- Laravel `12.x`, `13.x`
- PHP `8.2+`

Development Tools
-----------------

[](#development-tools)

The package includes a helpful command to speed up your development workflow:

- **`make:repository`** This command automates the creation of the following components for a specified model:

    - Repository Class
    - Repository Interface
    - Filter Class

**Usage Example:**

```
php artisan make:repository User
```

or

```
php artisan make:repository App\Models\User
```

Example Usage
-------------

[](#example-usage)

Practical example of how to use this package to manage and interact with a Post model.

It includes examples of a custom repository, filter, criteria, and controller usage.

### Post Repository

[](#post-repository)

The `PostRepository` class extends BaseEloquentRepository and demonstrates the use of the package's features for a Post model.

```
