Logic Of Repository Pattern Laravel
I am learning to use the Laravel framework.
I came across the repositories, said in several sites be a good practice of development.
I found some packages that help implement this practice in Laravel, but missed some features, but I think I'm failing to understand very well the logic and its benefits.
Considering studying that part, I created a package that shows how to think is this implementation, but I still have many questions.
Scopes and relations should be transferred to the repository or kept in the model?
How to implement the type functions
"increment(), decrement()" in the repository? or is it correct to call them on the controller?
$model = $repository->find($id); $model->increment();
You should have the relationships set in the model:
When you are talking to the model from within the repo you can then pull the relationship information if needed. The increment and decrement should be done in the repository.
Check out this quick article to get a better understating of what you are trying to achieve using the repository pattern:
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?