A base repository class for Eloquent with convenience methods that cover most queries. Useful to abstract away your persistence layer from your business code.
For Laravel 5.4 and above
composer require bulwark/repoman ~1.0The examples will use a hypothetical Eloquent model named User.
<?php
namespace App\Repositories;
use App\Models\User;
use Bulwark\Repoman\Repository;
class UserRepository extends Repository
{
protected function getModel()
{
return new User;
}
}Repoman is already integrated with Bulwark\Dream.
See Dream documentation for more information.
The $options key given by all get-methods takes the following format:
| Parameter | Value type | Description |
|---|---|---|
| includes | array | Array of relationships to eager load |
| sort | array | Array of sorting rules, e.g. [['key' => 'username', 'direction' => 'ASC']] |
| filter_groups | array | See Dream documentation |
| limit | int | Rows per page |
| page | int | The page to start from (use with limit) |
Note: If you use the controller of Dream it will automatically parse the request's query string into the correct format.
The examples will use a hypothetical Eloquent model named User.
Get all User rows
Get one User by primary key
Get User rows ordered by created_at descending
Get User rows where $column=$value, ordered by created_at descending
Get User rows where $column=$value
Get User rows by multiple where clauses ([$column1 => $value1, $column2 => $value2])
Get User rows where $column can be any of the values given by $values
Get the most recent User
Get the most recent User where $column=$value
Delete User rows by primary key
Delete User rows where $column=$value
This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
$ phpunitPlease see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.