Abstracting around the Query Builder for Controller and Jobs
I want to move all the logic of my application into Service classes. Once I do that there should no longer be any usage of the Models outside of the service classes. Currently my app has an API and a console app for running jobs.
I see my service classes being able to work with both the api and the jobs by providing the right methods. I want to have on the service class a method that I can use to retrieve records by filtering, side loading relationships, sorting and paginating. I want to be able to use the same method in the jobs. For that I was thinking to extract some generic classes for Filtering, Sorting, Includes, Pagination and be able to use them from the Controller and from the Jobs. Includes, Pagination and Sorting seem to be less complex. However, the filtering one would require building something pretty complex that in the end would resemble a lot the already existing Query Builder. The filtering should be able to handle ANDs, ORs, and all the operators available as well as the ability to filter by relationships (whereHas, has, or just using joins).
Does anyone have any ideas on how to abstract this or find a way to use the query builder in the filtering, sorting, etc classes?
Please or to participate in this conversation.