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

yidekoh556's avatar

How to convert Query Builder to Eloquent?

Hi, I have been searching for a list of all eloquent queries but no luck. So Can I just convert Query Builder Queries into Eloquent? For example.

Query Builder : DB::table('users')->where('name', 'John')->value('email')

Eloquent : Users::where('name', 'John')->value('email')

Will it work for every DB Query? Thanks for your answers.

0 likes
3 replies
nine's avatar

yes you can. a good way to test is tinker, try everything again and again.

1 like
lostdreamer_nl's avatar

Eloquent models will use the magic __call method to redirect unknown methods to the Query Builder.

So basically anything you can do on the DB:: class you can also do on your Model classes.

(pro tip: try out a real IDE like phpstorm + the ide-helper packages for laravel and you can click through all classes) too see how they work.)

1 like

Please or to participate in this conversation.