- Folder Structure
- Code Samples
- Other Properties:
- API Query Parameters Property
- All other Properties
The Repository classes are an implementation of the Repository Design Pattern.
Their major roles are separating the business logic from the data (or the data access Task).
Repositories save and retrieves Models to/from the underlying storage mechanism.
The Repository is used to separate the logic that retrieves the data and maps it to a Model, from the business logic that acts on the Model.
Every Model SHOULD have a Repository.
A Model SHOULD always get accessed through its Repository. (Never direct access to Model).
All Repositories MUST extend from
App\Ship\Parents\Repositories\Repository. Extending from this class will give access to functions like (
updateand much more).
Repository name should be same like it's model name (model:
If a Repository belongs to a Model whose name is not equal to its Container name, then the Repository must set the
$containerproperty like this:
$container='ContainerName'. See an example below
Note: If the Repository belongs to Model with a name different from its Container name, the Repository class of that Model must set the property
$container and define the Container name.
To enable query parameters (
?search=text,...) in your API you need to set the property
$fieldSearchable on the Repository class, to instruct the querying on your model.
$fieldSearchable of a
Continue reading to find more about those properties and what they do.
apiato uses the
andersao/l5-repository package, to provide a lot of powerful features to the repository class. such as
To learn more about all the properties you can use, visit the
andersao/l5-repository package documentation.