PHPackages                             littlebug/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. littlebug/laravel-repository

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

littlebug/laravel-repository
============================

The repository mode for laravel!

v2.0.7(4y ago)354.2k9MITPHPPHP &gt;=7.0.0CI failing

Since Nov 4Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Wanchaochao/laravel-repository)[ Packagist](https://packagist.org/packages/littlebug/laravel-repository)[ Docs](https://littlebug.vip)[ RSS](/packages/littlebug-laravel-repository/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (0)

laravel-repository
==================

[](#laravel-repository)

[![Progress](https://camo.githubusercontent.com/6bec38c95d3bc5cef451bec1575a98a2d810fddde9db1bb88847e98ccbad5950/687474703a2f2f70726f677265737365642e696f2f6261722f3130303f7469746c653d636f6d706c65746564)](https://camo.githubusercontent.com/6bec38c95d3bc5cef451bec1575a98a2d810fddde9db1bb88847e98ccbad5950/687474703a2f2f70726f677265737365642e696f2f6261722f3130303f7469746c653d636f6d706c65746564)[![Latest Stable Version](https://camo.githubusercontent.com/b22e49185cb9de3d23d27900d78d9d8a39b4306e0aebeadce29889aa07d8c6ae/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c656275672f6c61726176656c2d7265706f7369746f72792f762f737461626c65)](https://packagist.org/packages/littlebug/laravel-repository)[![Total Downloads](https://camo.githubusercontent.com/d86bee13de7458ab2992f0f870760bee91c2b2c87a7c02e206227e964844d2b6/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c656275672f6c61726176656c2d7265706f7369746f72792f646f776e6c6f616473)](https://packagist.org/packages/littlebug/laravel-repository)[![Latest Unstable Version](https://camo.githubusercontent.com/23c84a5a8b9e8fcabb3f648f804885ec321da654c981fd81d75d24490467f1d5/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c656275672f6c61726176656c2d7265706f7369746f72792f762f756e737461626c65)](https://packagist.org/packages/littlebug/laravel-repository)[![License](https://camo.githubusercontent.com/696f0d8e5771cdaa57f4c77520f8967c30c836a69857dcdafacc3839f2f3ce41/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c656275672f6c61726176656c2d7265706f7369746f72792f6c6963656e7365)](https://packagist.org/packages/littlebug/laravel-repository)[![GitHub stars](https://camo.githubusercontent.com/a0e50a5ffe24a81ca1cf3031a9a27d7362f33b87b23f08b9ee5549c8639ba6ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f57616e6368616f6368616f2f6c61726176656c2d7265706f7369746f72792e737667)](https://github.com/Wanchaochao/laravel-repository/stargazers)[![GitHub issues](https://camo.githubusercontent.com/d3164a9093872b87d2c6bb369c107f4fc16a0d1c66a586e52b394cbb561cbcce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f57616e6368616f6368616f2f6c61726176656c2d7265706f7369746f72792e737667)](https://github.com/Wanchaochao/laravel-repository/issues)[![GitHub forks](https://camo.githubusercontent.com/e30ea3620d25abf0833c6bd47eb1ef10b2b7dfddeef8f96f4dc2aae478bbbccf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f57616e6368616f6368616f2f6c61726176656c2d7265706f7369746f72792e737667)](https://github.com/Wanchaochao/laravel-repository/network)[![Laravel](https://camo.githubusercontent.com/b2506ab39f3fd6a46522c1856bbe3f887a405f25ebd57b65b934c46184c0ddf0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c253230253545352e352d737570706f72742d627269676874677265656e2e737667)](https://github.com/laravel/laravel)

[切换中文](./README.zh-CN.md) | [Usage of Repository](https://wanchaochao.github.io/laravel-repository/?page=repository)

Introduction
------------

[](#introduction)

`laravel-repository` provides the basic `repository` class for [laravel](https://laravel.com/)[model](https://learnku.com/docs/laravel/5.5/eloquent/1332) The package was made to provide more More external methods, and more friendly editor prompts; layering the code, `repository` is responsible for external business logic processing, `model` is only responsible for the definition of the fields, attributes, query conditions, and return values of the data table. It does not participate in specific logical operations, and does not serve the control layer.

### Relative to the direct use of `model` advantages:

[](#relative-to-the-direct-use-of-model-advantages)

- Solve the problem that `model` does not automatically handle extra fields when adding or modifying
- Optimize chained calls for `model` queries, query directly using arrays
- Automatically process corresponding associated data queries through query conditions and query fields
- Provides a more friendly editor prompt

Install
-------

[](#install)

### Installation requirements

[](#installation-requirements)

- PHP &gt;= 7.0.0
- Laravel &gt;= 5.5.0

### 1.1 Install package

[](#11-install-package)

```
composer require littlebug/laravel-repository:2.0.*
```

or add this to require section in your composer.json file:

```
"littlebug/laravel-repository": "2.0.*"
```

then run composer update

### 1.2 Use the command to generate `model` and `repository`

[](#12-use-the-command-to-generate-model-and-repository)

Suppose you have users in your database, or you replace users with the table names in your database.

```
php artisan core:model --table=users --name=User
```

The command will be at:

- Generate `User` file under `app/Models/` file
- Generate `UserRepository` file under `app/Repositories/` file

### 1.3 Using `repository` in the controller

[](#13-using-repository-in-the-controller)

```
