A sharp deconstruction of the "magic" behind Eloquent that reveals the clever plumbing of PHP's magic methods. It’s essential viewing for developers who want to understand the engine rather than just driving the car.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
What Actually Happens When You Call dd() on a Laravel Model?Added:
Welcome back to the channel. I'm Puneet Bhatia, your host, and today we will going to talk about something interesting.
So, you can see here, yesterday we were talking about this one, and we found that it is doing something different thing, right? So, as we can see, we are what we are doing is we are just DD the post, which is we are getting first post, which is published before today.
So, it is simple enough, and we are also getting it. If I reload it, it is the same result, right?
But, when I do DD over here, what happens? You may think that we will going to get the post model, but we are actually getting the select star query, which is even not related to this initial query which we had. So, what's happening behind the scenes? Why we are getting this one, right?
Because it first says we are returning the key value, which is the model, of course, and that is actually accurate enough, because if I don't do this, it shows me the model, right? So, that is the correct. So, what's happening behind the scenes? So, here one concept, which is which Laravel uses behind the scenes, is using. So, what what hap what happens? Let me uh explain you a bit here.
And then we can even do going to do some experiment as well after that. So, if we go to this post model, and we just go to the this model, here we can see this forward calls, right?
And this is where uh everything happens.
So, if I go uh mostly into uh this magic method called call, so whenever any method does not exist in PHP class, they try to see if there is a call method. So, if none of the method exists, they just pass that method and parameters into the call magic method, which is simply a PHP thing, right? So, after that what happens is it calls forwarded call with new query, a method, and object. So, what they do is they create a builder object and forward that method call into that particular builder class.
And this new builder is just creating a uh query builder for current model.
So, what here we can see is what we're going to happen is they will do forward call over here, and they will just going to call that particular method if exist. So, if it will not it it does not exist at all, it will going to throw an exception, and which will be also interesting to see what happened.
So, let's let me just do DD over here for a sake.
Yeah, right? And if I reload this, see, we are got getting here over here. And if I do simply the method name, dollar Okay, whatever, everything. So, let's keep the See, we are we are calling limit method or something like that on this, which is somewhere even was forwarding before.
Oh, wait. So, we should even we should do dump over here, not the DD. So, at the end of the stuff, we can see DD.
See, so it was forwarded from the model to builder class with the call forwarding trait.
So, that is what happening over here, simply. So, if So, what will happen when I say XYZ over here and do reload?
Uh most probably we I hope So, we are getting some exception, which says Oh, it says post instead of model. So, I thought it will say the builder class, but it is not the builder class, because I guess it's about that particular stuff. So, what I can say here is I can even do where or something like that. Oh, I'm sorry.
Yeah, where category maybe some category, and if I do DD over here, right? And if I reload this, it will say category something like this, right? And even I can do DD raw SQL, right? And which will have some kind of this query. So, it is interesting. I don't know if you think let me know in the comment if Laravel should prevent this or not. I don't know.
Less So, yeah, this is what it was. Thanks for watching, and let me know into the comments if you want to see more videos like this.
Thanks for watching. Bye. See you.
Related Videos
VALORANT's Latest 'Exclusive' Tier Bundle is Rough...
KangaValorant
17K views•2026-05-28
Flight Attendant Mocks Poor Looking Black Woman — Mid Air Announcement Exposes Her Real Power
SkyboundStories-b4r
184 views•2026-05-28
I FIXED My Friend’s Blown Turbo RX-8… Then Sold It
Cameron-RX8
134 views•2026-05-28
NewsWatch 12 at 5: Top Stories
NewsWatch12
1K views•2026-05-28
Simon Jordan & Danny Murphy deliver PREDICTIONS for Arsenal's Champions League FINAL with PSG
talkSPORTArsenal
6K views•2026-05-28
Botting is OUT OF CONTROL in Classic WoW (Again)...
SolheimGaming
108 views•2026-05-28
The "AI Job Apocalypse" is CANCELLED!
WesRoth
9K views•2026-05-28
STREET FIGHTER 6 - INGRID Story Walkthrough @ 4K 60ᶠᵖˢ ✔
RajmanGamingHD
12K views•2026-05-28











