REPOSITORY PATTERN IN LARAVEL 5.4
UNDERSTANDING REPOSITORY PATTERN IN LARAVEL 5
Repository : Repository acting as a intermediate layer between client business logic and data source layer.
Why to use REPOSITORY DESIGN PATTERN
The repository mediates in between the business layer and data source layer.
It persist the change in the object or entity of business logic to data source layer so that the client gets the similar data.
Repository request the data from data source, and provide that data to client business logic.
It also seperates the data source from the client business logic.
It provides a substitution point for unit test.
It centralize the data logic so that data can be find easily.
It provides the architecture which can ne used in any of web applications.
Data source layer:
It can be a data base or web service.
It is the layer of repository pattern which stores all the data and act as an server.
Client business logic:
client business logic will query data and acts as an client.
Suppose client business logic want to query some data from the data source then what business logic will do is, it will send the query to repository and repository will further query the data to data source and it will get the data and map the data to business entity and send business entity to client business logic.
If client business logic wants to save a little information in data source, then it will send a business entity that will contain the data which it want to save and send it to repository. Then the repository will save that data in data source.
Example: for better understanding let us take an example:
Business entity :
It can be the id, name, age, gender, occupation of a person.
Repository of person:
find person(int id), update person(), save person(), get person(), delete person(int id), create person(),
It contains the whole data of business entity or it contains the person table.
If client want some information from person table then it will call find person method by passing person id . Then client business logic will get the information like name, gender, age, occupation and all the fields related to the person.