Introduction
Just to remember laravel repository is not mandatory for laravel projects but represent as collection of specific type of entities where we write those functions and information on interface and then implement them on repositories to provide a cleaner way and easy to read for our controllers and can be used repetitively (over and over) .
Repositories interface --------------- belongs to -----> domain layer
Implementation repositories ------- belongs to ------> application-service layer
Domain Layer
The domain model layer contains information and functionality related to what it means to be a User. It should map conceptually onto something that exists physically in the real world or a clearly defined concept in the problem space.
Service Layer
The service contains information and functionality related to performing atomic units of work. It should map conceptually onto tasks that are performed on or by members of the Domain model. A single atomic task performed by clicking a button in the application generally involves many members of the Domain working together.
Repositories interface --------------- belongs to -----> domain layer
Implementation repositories ------- belongs to ------> application-service layer
Domain Layer
The domain model layer contains information and functionality related to what it means to be a User. It should map conceptually onto something that exists physically in the real world or a clearly defined concept in the problem space.
Service Layer
The service contains information and functionality related to performing atomic units of work. It should map conceptually onto tasks that are performed on or by members of the Domain model. A single atomic task performed by clicking a button in the application generally involves many members of the Domain working together.
Benefit of Use
1. Using repositories make our controllers less verbose , loosely coupled and easier to read.
2. Represent as concept of storage collection for specific type of entitiy (model)
3. Abstract storage mechanism for authoritative collection of entities.
4. Freedom to swap out data stores at a later date.
Without Repository
With Repositories
4: Create Backend Service Provider
5: Update Providers in Config/App.php
6: Update Your Controller
References
http://shawnmc.cool/the-repository-pattern#disqus_thread
http://vegibit.com/laravel-repository-pattern/
http://stackoverflow.com/questions/31453570/laravel-5-repository-inside-service-provider
http://stackoverflow.com/questions/31453570/laravel-5-repository-inside-service-provider
No comments:
Post a Comment