Eloquent's New Chaperone Method
Вставка
- Опубліковано 17 вер 2024
- The latest version of Laravel 11 ships with a new chaperone method for Eloquent models. Cutely named, it solves an N+1 problem that likely every one of us has encountered at some point or another.
Watch thousands of videos, track your progress, and participate in a massive Laravel community at Laracasts.com.
Laracasts: laracasts.com
Laracasts Twitter: / laracasts
Jeffrey Way Twitter: / jeffrey_way
That outro was awesome, loved it
Love your videos, here and at laracast.
Are you planning to discuss all the new features that were announced at the recent Laracon? That's much needed now.
Yes, on Laracasts.
@@Laracastsofficial Thanks! 👏
Jeffrey really has a knack for educating complete beginners like me😅. Bravo🎉
Can't we just return $series->title immediately inside the map function?
you can, the examples sometimes that they show are not completely clear on the use cases
That's what I was thinking. I guess chaperone might be useful if you're a senior dev trying to prevent a junior from making the mistake though.
I updated to 11.22 because it happened to be the feature I was needing at the moment. It's not that we don't know how to do it manually. The point is that it's easy to forget to do it and end up with the n+1 query problem. It's just handy. And about the naming: I think that "goAlong" would be nice too: $this->hasMany(Video::class)->goAlong()->orderBy('position');
Hmm I would probably just pass the $series model to the map callback function with use($series)
First thing I thought about too.
It’s a silly example. The point is you will often not have immediate access to the parent series model.
jeffrey, yes we need to know the internals please
Best Teacher ever!
very helpful thank you 🙌
Thanks ❤
That's amazing
Besides applying it to the episodes, do we need to apply it to the inverse relation (series)?
Is defer also available?
Quick question, is chaperone() available only for hasMany relationships or can we use it for belongsToMany(), if we can't, anyone knows why?
so let me get it strait, from what i see chaperone remove one extra loop meaning it's setting the relation object on episodes collection instantiation instead of creating the collection and then looping it and setting the rel.
What's the theme phostrome jeff?
Are you using vim motions?
What's the music in intro wanna make that my ringtone so catchy.
Can I use it on Larave 10.x ?
Thank You ❤