BrainyT's avatar

Eloquent on model

Controller or Model which is best to put eloquent queries?

0 likes
4 replies
marosmjartan's avatar

It depends. If it is a small query and is used for one page or for one api endpoint, then you should put it in controller. if it's a more complex query, then make custom class as a Service for the querry. If it has to be a query that takes care of relationships or it is fundamental for the model, then put it into the model.

Snapey's avatar

I put queries in the model about 0.01% of the time

Otherwise, controller, service or action class.

Please or to participate in this conversation.