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

kalvinmizzi's avatar

Eloquent Builder whereId

I just confirmed this exists and works... yet I can't find any documentation or even function definition anywhere in Laravel. How does this mythical method work?

0 likes
7 replies
kalvinmizzi's avatar

@vincent15000 I saw this article and it is the ONLY mention of it on the web that I could find... which is strange

1 like
kalvinmizzi's avatar

I just found it seems to work with all columns... like whereName('abc')

Yet still can't find documentation?

1 like
vincent15000's avatar

@kalvinmizzi I effectively don't find any documentation.

But is there really any need to use this method ?

I always use find.

Tippin's avatar
Tippin
Best Answer
Level 13

@kalvinmizzi Those calls end up in the core builder. Eloquent does much of this magic thanks to PHP's magic __call and __callStatic methods.

User::whereId()->first();

That would first hit __callStatic magic method on the core model:

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Eloquent/Model.php#L2331-L2334

Which is forwarded to __call now that the model is instantiated:

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Eloquent/Model.php#L2311-L2322

It ends up giving a new Eloquent builder, but it will not match any given methods, thus forwards to the core query builder

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Eloquent/Builder.php#L1864

And then the core builder handles the magic once more

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Query/Builder.php#L3776-L3778

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Query/Builder.php#L1890-L1924

Please or to participate in this conversation.