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.
Approfondir
Prérequis
- Pas de données disponibles.
Prochaines étapes
- Pas de données disponibles.
Approfondir
What Actually Happens When You Call dd() on a Laravel Model?Ajouté :
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.
Vidéos Similaires
She Lost Her Car... But We Still Helped Her!
RecoveryBoyz
129 views•2026-05-30
Deadly Got Talent Auditions You Should NEVER Try at Home!
gottalentglobal
5K views•2026-05-29
Cozy Cottage Jazz | Warm Morning Cafe Ambience 🌸
villagejazzhouse
846 views•2026-05-29
DeBoer Wants Alabama Tougher, Texas Tech Calls out the Texas Longhorns | TNR 5/29/26
NextRoundLive
2K views•2026-05-29
Smart Working Techniques for Faster and Safer Jobs Part 54✅ #construction #adamrose #workers
worksmart-98
2K views•2026-05-29
LIVE: Move Into Friday with Special Guest Ed O'Brien | Morning Becomes Eclectic
kcrw
778 views•2026-05-29
On Bended Knees - Jekalyn Carr (Official Live Worship)
halalafrika
7K views•2026-05-29
Black Hills To Badlands In A Nova Bought SIGHT UNSEEN-Going To Towns Tour with HUNDREDS of CLASSICS!
ViceGripGarage
52K views•2026-05-29











