Download the PHP package guardian360/repository without Composer
On this page you can find all versions of the php package guardian360/repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download guardian360/repository
More information about guardian360/repository
Files in guardian360/repository
Package repository
Short Description Repository pattern used to abstract the database layer.
License MIT
Homepage https://github.com/guardian360/repository
Informations about the package repository
Guardian360 Repository
A base repository for Eloquent models.
Requirements
- PHP >=7.0.0
- PHP MongoDB driver (optional)
Installation
Install via composer.
Usage
First, you should create your repository class. You can do this manually or by
using Artisan by doing $ php artisan make:repository UserRepository
. Your
repository must extend \Guardian360\Repository\AbstractRepository
and
implement the model()
method.
By implementing the model()
method, you are telling the repository what model
class you want to use. Next, in our case, it seems only logical to have a User
model. Why don't we create one?
Finally, you may use the repository in your controller, or anywhere else really.
Examples
Fetch a list of all users.
Find a user.
Find a user by an attribute.
Find all users by an attribute.
Create a new user.
Update an existing user.
Delete an existing user.
Specifications
Specifications allow you to apply very specific conditions to the repository's
query. You may use Artisan to generate a Specification class for you, using
$ php artisan make:specification UserIsAdmin
, or you may do so manually.
Your specification must satisfy the
\Guardian360\Repository\Contracts\SpecificationContract
contract.
Then, you may push the Specification to the repository in your controller. You may use as many Specifications as you like.
Credits
This package is inspired by the following awesome packages:
- https://github.com/bosnadev/repository
- https://github.com/andersao/l5-repository
- https://github.com/ollieread/laravel-repositories
Thanks guys, I could not have done this without you. :)
All versions of repository with dependencies
illuminate/console Version >=5.5
illuminate/database Version >=5.5
illuminate/pagination Version >=5.5