Closed JohnnyWalkerDigital closed 7 months ago
@JohnnyWalkerDigital this package is not only about the repository pattern. I like when the business logic and DB operations separated, this way I dont have to support eloquent queries all over the project. I keep all kind of searches inside the repository in one place so its easy to manage, update or totally remove part of functionality. Its a big pain on my other projects where Eloquent queries were used everywhere in the project (600+routes), so its extremely hard to maintain them. In my case I have to maintain only 1-2 functions and it saves a lot of time. Also there is always a possibility to swap repository, or service or both globally for the whole project. This package supports CRUD, caching for repositories and base search from the box, so everything that is required just to create repository, service and bind them. I find this approach the most comfortable for me personally thats why this package exists. It has nothing common with the post you sent me, I believe you did not read the description of the package
Scenario : Creating a user :
Creating validation services like UserStoreValidator.
Calling the validator inside the controller and passing the user's input to the validator.
Creating a service class called UserCreator and adding a create method to that.
Creating a UserRepositoryInterface and a UserRepository class, adding a createUserFromArray method to it, or sometimes just calling the the createRaw(array $data) method from my AbstractEloquentRepository implementation. The method is called from my user creator service.
And doing some other jobs like sending welcome_email by Events which are fired inside my service classes.
My user creating scenario :
1) Make sure repository and service exists (there are commands to generate them)
2) Create request for validating it, e.g StoreRequest (also could be generated by package)
3) Call $this->userService->create($request->validated());
You have a regular validation like everywhere on other projects.
You have a service which is also a common part of a well-structured project
So there is no any pain
to develop like this.
Why?
What benefits does it give you over using Eloquent?
https://laracasts.com/discuss/channels/general-discussion/reasons-i-abondoned-repository-pattern-in-laravel