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

КОМЕНТАРІ • 27

  • @brunoggdev6305
    @brunoggdev6305 7 днів тому +1

    That outro was awesome, loved it

  • @fakerealnews1
    @fakerealnews1 7 днів тому +3

    Love your videos, here and at laracast.

  • @im-nazmul
    @im-nazmul 7 днів тому +3

    Are you planning to discuss all the new features that were announced at the recent Laracon? That's much needed now.

  • @jonathanjohnson2785
    @jonathanjohnson2785 5 днів тому

    Jeffrey really has a knack for educating complete beginners like me😅. Bravo🎉

  • @tariksadiku4723
    @tariksadiku4723 7 днів тому +16

    Can't we just return $series->title immediately inside the map function?

    • @SXsoft99
      @SXsoft99 7 днів тому +2

      you can, the examples sometimes that they show are not completely clear on the use cases

    • @ricardoruiz3986
      @ricardoruiz3986 3 дні тому +1

      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.

  • @erickdeazevedolima1763
    @erickdeazevedolima1763 7 днів тому

    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');

  • @eyemazed
    @eyemazed 7 днів тому +6

    Hmm I would probably just pass the $series model to the map callback function with use($series)

    • @bojackhorsemanners
      @bojackhorsemanners 7 днів тому +1

      First thing I thought about too.

    • @jeffreyway520
      @jeffreyway520 7 днів тому +1

      It’s a silly example. The point is you will often not have immediate access to the parent series model.

  • @grise123
    @grise123 День тому

    jeffrey, yes we need to know the internals please

  • @itisconsulting
    @itisconsulting 6 днів тому

    Best Teacher ever!

  • @tahashaban-du6fi
    @tahashaban-du6fi 7 днів тому

    very helpful thank you 🙌

  • @AMoktar
    @AMoktar 7 днів тому

    Thanks ❤

  • @Md.NajmulHasan-xo9qh
    @Md.NajmulHasan-xo9qh 7 днів тому

    That's amazing

  • @RodrigoMendoza7
    @RodrigoMendoza7 6 днів тому

    Besides applying it to the episodes, do we need to apply it to the inverse relation (series)?

  • @DeTechDivus
    @DeTechDivus 7 днів тому +1

    Is defer also available?

  • @draiczon
    @draiczon 2 дні тому

    Quick question, is chaperone() available only for hasMany relationships or can we use it for belongsToMany(), if we can't, anyone knows why?

  • @SXsoft99
    @SXsoft99 7 днів тому

    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.

  • @ravisorathiya1756
    @ravisorathiya1756 4 дні тому

    What's the theme phostrome jeff?

  • @jalex2862
    @jalex2862 6 днів тому

    Are you using vim motions?

  • @pratikbhujel
    @pratikbhujel 7 днів тому

    What's the music in intro wanna make that my ringtone so catchy.

  • @borakayalar
    @borakayalar 7 днів тому

    Can I use it on Larave 10.x ?

  • @RockstahRolln
    @RockstahRolln 7 днів тому

    Thank You ❤