Download the PHP package sebastian-berc/repositories without Composer
On this page you can find all versions of the php package sebastian-berc/repositories. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sebastian-berc/repositories
More information about sebastian-berc/repositories
Files in sebastian-berc/repositories
Package repositories
Short Description Flexable Laravel ~5.0 Repository Library.
License MIT
Homepage https://github.com/SebastianBerc/Repositories
Informations about the package repositories
Repositories
Install
Via Composer
Usage
Make your own repository with extends the abstract \SebastianBerc\Repositories\Repository
class and implement takeModel
method:
Usage with Dependency Incjection
Wherever Laravel provides dependency injection you can attach your repository like this:
Usage without Dependency Injection
If you need a repository without dependency injection you can use the static method like this:
Methods
This gives you access to methods such as...
creating a new query to get all results from repository:
[Need fix] creating a new basic where query clause on model and returns results:
creating a new query with pagination:
saving a new model and return the instance:
saving or updates the model in the database.
Also you can pass a model:
even with additional attributes:
delete the model from the database:
find a model (only first result) by its primary key:
find a model (only first result) by its specified column and value:
find a model (only first result) by its specified columns and values presented as array:
return total count of whole collection based on current query:
fetch collection ordered and filtrated by specified columns for specified page and this method will return instance of LengthAwarePaginator
:
fetch simple collection without LengthAwarePaginator
, but ordered and filtrated by specified columns for specified page:
Eager loads
If your model has a relationship and you want to load it, you can do this with query results by calling the with
method, for example:
Criteria
Sometimes you need to prepare repeatable query that displays, for example, only active and not banned users or the latest news from the week before - to do this you can use a criteria:
Now you can use your criteria with repository:
Transformers
The data from your repositories can be sent to different places, for example, it may be your site or the same data with the exclusion of several columns can be shared with Web API, you can achieve through class Transfomer
:
When you have your own Transformer
you can apply it to repository:
Cached repository results
To hold query results in a cache just add the implementation of the interface ShouldCache
to your repository:
And its magic because from now everything will be cached :).
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Sebastian Berć
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of repositories with dependencies
illuminate/contracts Version ~5.0|~5.1|^6.0|^7.0
illuminate/database Version ~5.0|~5.1|^6.0|^7.0