Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andhirto's avatar

Query Builder Placement

Hello, . I am new and learning laravel for now, if I write a 'Query Builder', where is my best place to place it? . What if I place it in the 'Eloquent Model' as a static function? please give your answer about the best placement for this . Thanks all ^ _ ^

0 likes
3 replies
jlrdw's avatar

I don't know about others but I use Query scopes and they are in the model.

Especially select type statements sometimes insert and update I do in the controller.

clc5889's avatar

Refer to the model in the controller for the object or function you're building. The controller can pass the query results to the view.

andhirto's avatar

Thanks @jlrdw and @clc5889 for your answer, I will try it for some simple projects later. Thanks for give the answer ^_^

Please or to participate in this conversation.