Download the PHP package doctorbeat/eloquent-repository without Composer
On this page you can find all versions of the php package doctorbeat/eloquent-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download doctorbeat/eloquent-repository
More information about doctorbeat/eloquent-repository
Files in doctorbeat/eloquent-repository
Package eloquent-repository
Short Description A repository for eloquent models. Using this makes the model appear to have a sigle responsibility
License MIT
Informations about the package eloquent-repository
eloquent-repository
A repository for eloquent models. Using this makes the model appear to have a single responsibility and thus makes them unit-testable in isolation
Installation
Via composer:
Why a respository?
Eloquent is great for its simplicity but this simplicity makes that Eloquent models breaks the 'single responsibility" principle. An Eloquent model is both a entity (property bag) AND dealing with database interaction (select, insert, update, delete). And this makes that you can not mock your models in isolation. You need the entity functionality but want to mock the database interaction.
This problem is further shown in the fact that Eloquent models use static functions like find(), all() and where().
In comes the Eloquent Repository which make you able to use a model as an entity/property bag moves all database interaction methods to the repository. The repository comes with an interface which can be mocked.
Methods and api
These methods are available on the repository and have an api equal to the corresponding Eloquent method:
- save
- delete
- push
- touch
- all
- find
- where*
- all other static methods
Relations
To get relations from the repository use these methods:
These examples assume that you have defined parent and children as relations on the model!