Repository Base Manager
#
IntroductionThe Repository Base Manager is shipped with more facilities for better and faster usage for repositories.
This is an abstract class, mostly inherited by MYSQL
repositorty or MongoDB
repository.
The class handles all types of data manipulation and retrieval such as Creating
Updating
Retrieving
and Deleting
records from database.
#
Wrapping Model into resource instanceAs model data needs to be more customized, for instance defining the full image url, then can be done easily by using Laravel Resources.
The repsotiroy model can be wrapped into the repository resource class using the wrap method
The wrap method will return an instance of UsersResource
class.
tip
The wrap
method can also accept an array of data, if that is the case, then the data will be passed to the repository model and creates new instance before sending it to the repositorty resource.
#
Wrapping collection of modelsThis works exactly the same as the wrap
method, except that it works with list of modesls.
The wrap method will return an list of UsersResource
instances.
info
The previous example is for demonstration purposes only, you can use the list
method which combines the listModels
with wrapMany
method.
#
Create and wrap the modelOnce we created the record using create
method, we may need to return it to the response by using the wrap
method, there is a short method for creating and wraping the resource directly using createWrap
method.
This will first call the create method
which will return an instance of the repository model, then it will be passed to the repository resource class.
#
Update and wrap the modelSimilar to the createWrap
method but with the update
This will first call the create method
which will return an instance of the repository model, then it will be passed to the repository resource class.