bulwark / repoman
Requires
- bulwark/dream: ~1.0
- illuminate/database: >=4.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.7
- satooshi/php-coveralls: dev-master@dev
This package is not auto-updated.
Last update: 2024-11-10 06:28:13 UTC
README
Introduction
A base repository class for Eloquent with convenience methods that cover most queries. Useful to abstract away your persistence layer from your business code.
Installation
For Laravel 5.4 and above
composer require bulwark/repoman ~1.0
Implementation
The 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; } }
Options
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:
Note: If you use the controller of Dream it will automatically parse the request's query string into the correct format.
API
The examples will use a hypothetical Eloquent model named User
.
get (array $options = [])
Get all User
rows
getById ($id, array $options = [])
Get one User
by primary key
getRecent (array $options = [])
Get User
rows ordered by created_at
descending
getRecentWhere (string $column, mixed $value, array $options = [])
Get User
rows where $column=$value
, ordered by created_at
descending
getWhere (string $column, mixed $value, array $options = [])
Get User
rows where $column=$value
getWhereArray (array $clauses, array $options = [])
Get User
rows by multiple where clauses ([$column1 => $value1, $column2 => $value2]
)
getWhereIn (string $column, array $values, array $options = [])
Get User
rows where $column
can be any of the values given by $values
getLatest (array $options = [])
Get the most recent User
getLatestWhere (string $column, mixed $value, array $options = [])
Get the most recent User
where $column=$value
delete ($id)
Delete User
rows by primary key
deleteWhere ($column, $value)
Delete User
rows where $column=$value
Standards
This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.