Eloquent Polymorphic Relations: Properly Explained

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 48

  • @andywong2244
    @andywong2244 2 роки тому +1

    i was able to get the concept behind polymorphism at the 1st 3 minutes of your explanation Povilas! you teach very well!

  • @wtalkie
    @wtalkie 10 місяців тому

    Great explanation as always. You're the go-to channel for anything laravel-related.

  • @heitorferreira964
    @heitorferreira964 3 роки тому +3

    Thank you, your explanation save my day, I was very confused at beginning and I watched this lesson and debug many times until got the trick how it works under the hood.

  • @shafqatalinawaz6218
    @shafqatalinawaz6218 2 роки тому +2

    Thanks for sharing. I now understand perfectly how to use polymorphic relationships.

  • @kevinnacario359
    @kevinnacario359 4 роки тому +4

    Thank you so much!!! Was able to get the point of Polymorphic right of the bat.
    Definitely worth it. Hoping I could take your course but it seems its too expensive for me at the moment.

  • @RaphaelPinheiroDantas
    @RaphaelPinheiroDantas 4 місяці тому

    thank you for your time. learned after 3 years. you are awesome

  • @reesss4
    @reesss4 2 роки тому

    This is by far the best explanation I have seen! Thank you!

  • @redward4383
    @redward4383 3 роки тому

    Thank you so much, i had this kind of issue,but wasn't aware that these relationships actually exist, you've explained it very well.

  • @susanjoshi5948
    @susanjoshi5948 5 років тому +2

    I wish real life relationships were this simple. :D Lit tutorial.

  • @prianasaputra7583
    @prianasaputra7583 Рік тому +1

    Thanks, Now I understand this topic.
    Thank you sho much.

  • @kmaphane
    @kmaphane Рік тому

    Best explanation I found. Thanks a mill

  • @adnanasad4674
    @adnanasad4674 9 місяців тому

    Thanks, I have one question how will we reserve it means Photo::get() and It should fetch relationship data from relevant table example post or product.

  • @fnfal113
    @fnfal113 3 місяці тому +1

    Great video, thanks.

  • @VadimBesedin
    @VadimBesedin 4 роки тому

    As always - great explanation with examples. Thank you

  • @Hiltaku
    @Hiltaku 4 роки тому

    Thanks! Love the example. Makes the concept very easy to understand

  • @georgenikou
    @georgenikou 4 роки тому +2

    Really well explained, thank you very much for this!

  • @WaheedSindhani
    @WaheedSindhani 4 роки тому

    How do we retrieve all data with relations.

  • @ashique12009
    @ashique12009 3 роки тому +2

    Nicely explained.
    So if we have 3 tables like posts, products and images then we can make polymorphic relationship to bring data in optimized way. This can be done if we create two photo tables one is for post_photos and another is product_photos but for polymorphic relation we can reduce one table here.
    Thanks.

  • @VadimBesedin
    @VadimBesedin 4 роки тому

    But if my Models should have only one photo per record, having regular BelongsTo would be totally enough. Am I right?
    Posts
    ---id
    ---text
    ---image_id
    Users
    ---id
    ---name
    ---image_id
    Images
    ---id
    ---filename
    Or there are still advantages to use Polymorphic Relations in this case?

    • @PovilasKorop
      @PovilasKorop 4 роки тому

      If you have only those models strictly, then yes, your structure is good. But if in the future you're planning to have, for example, Comments with image_id or something else with image_id, polymorphic structure would allow you to achieve those new fields without changing any structure of DB cause you would reuse the same images database table.

  • @anissmarrouch282
    @anissmarrouch282 4 роки тому

    i was confused on this i am doing it in rails its different code wise but im assuming its the same concept thank you for the video and for the excellent explanation

  • @Egadirov
    @Egadirov 6 років тому +1

    Great example, thanks!

  • @nahueljj
    @nahueljj 4 роки тому +1

    how to update? i have Polymorphic tags, and i can store success but i cant update fine, the result contact the tags,for example
    #hello #word
    and i add , #one.. the result in my input is
    #hello #word #one #hello #word #one
    my code..
    $tags_name = explode(' , ' , $request->tags_name);


    foreach($tags_name as $tag_name)
    {
    $post->tags()->attach(Tag::updateOrCreate(['name'=>$tag_name]));
    }

    • @PovilasKorop
      @PovilasKorop 4 роки тому +1

      What is the error that you're getting?
      Maybe you shouldn't to ->attach() but instead create things manually, like PostTag::create('taggable_id' => $post_id) ... etc? (not sure what your polymorphic model is called, assumg PostTag)

    • @nahueljj
      @nahueljj 4 роки тому

      Hi, thx for the answer,
      My problem is that I don't think I'm using the most optimal solution to update the registry, since I'm removing the tags with dettach and then adding them again ... es.stackoverflow.com/questions/418957/como-hacer-un-update-en-una-tabla-polimorfica,

    • @PovilasKorop
      @PovilasKorop 4 роки тому +1

      @@nahueljj I think it's fine.

  • @linaktashifteam1826
    @linaktashifteam1826 5 років тому +1

    very clear explication, thanks

  • @cardboarddignity
    @cardboarddignity 3 місяці тому +1

    Hello from 2024. Still great video

  • @eli-thegreatdiscovery
    @eli-thegreatdiscovery 7 місяців тому

    Great video.

  • @opentech5972
    @opentech5972 6 років тому

    That mechanical keyboard sound, satisfying.

  • @avfoxstudios3226
    @avfoxstudios3226 2 роки тому

    well explained...bravo

  • @rahwee_khum
    @rahwee_khum 5 років тому

    Thank you for your useful video.

  • @md.rakibuddinrana3765
    @md.rakibuddinrana3765 3 роки тому

    Awesome🥰
    thank you

  • @dedecovasco
    @dedecovasco 4 роки тому

    Awesome!! Thank you very much

  • @twentxx
    @twentxx 2 роки тому

    Thanks very much, but this video not include Factories and Seeders

  • @asatbekxalimjonov4005
    @asatbekxalimjonov4005 3 роки тому +1

    amazing

  • @windigo000
    @windigo000 3 роки тому

    cool. 👍 i just can't bring myself to liking this aproach. one-too-many sleepless nights with slow db without keys. :) but it might have it's uses.

  • @topalidinka
    @topalidinka 3 роки тому

    Thank you :)

  • @slablife
    @slablife 5 років тому

    Excellent video… you just saved my butt! Do you have any Udemy courses?

    • @PovilasKorop
      @PovilasKorop 5 років тому +1

      Thanks Mike. Not on udemy, but on teachable - see laraveldaily.teachable.com

  • @Виталий96-к4я
    @Виталий96-к4я 4 роки тому

    !!!!!
    Thank you very match !

  • @unomas9686
    @unomas9686 4 роки тому

    You are the best teacher !
    From russia. putin-juilo

  • @NMND.
    @NMND. 2 роки тому

    AAAARGH SO BRIGHT! x_x

  • @shubhamsahuSD
    @shubhamsahuSD Рік тому

    Got it

  • @MohamedTrabelsi-g8p
    @MohamedTrabelsi-g8p 5 місяців тому

    Great explanation From 2024

  • @SalmanMemon_Sam
    @SalmanMemon_Sam 5 років тому

    best

  • @vitaminabe
    @vitaminabe 3 роки тому

    thank you, very informative!