Laravel 6 Advanced - e3 - Polymorphic Relationships

Поделиться
HTML-код
  • Опубликовано: 3 июл 2024
  • Polymorphism is just a fancy word for the concept that objects can take different shapes as long as they follow the same interface. In this episode, we are exploring One To One (Polymorphic) relationships, One To Many (Polymorphic) relationships and Many to Many (Polymorphic) relationships by example.
    For the best experience, follow along in our interactive school at www.coderstape.com
    Documentation
    laravel.com/docs/6.0/eloquent...
    DigitalOcean Referral
    m.do.co/c/7dce5364ef4d
    Hit us up on Twitter with any questions or comments @codertape ( / coderstape )
    About This Course
    Ready to level up your Laravel skills? This series is for you, follow along as we uncover the advanced Laravel features that actually make Laravel the most popular php framework. We'll have lot of tips and tricks along the way. Are you ready?

Комментарии • 178

  • @JackbearAmine
    @JackbearAmine 4 года назад +29

    Thank you for all of your efforts in explaining Laravel for us in easiest way. May the success that has come your way today lead you to a bigger achievement in the years to come.

  • @Chmelewsky
    @Chmelewsky 2 года назад

    this is one of the best laravel tutorials i've seen. subscribed!

  • @colinrdixon
    @colinrdixon Год назад

    puts it all into perspective!! super appreciate you for this video.

  • @coolcha
    @coolcha 3 года назад

    This video was so nice. It made such a complex topic so much simpler to follow and with examples.

  • @pavanobhan1105
    @pavanobhan1105 2 года назад +1

    You are awesome. I was having hard time understanding the relationship concepts through documentations. After watching your video, now I have crystal clear idea on relationships. Thanks a lot. Subscribed.

  • @lysokkong5826
    @lysokkong5826 4 года назад

    Crystal clear explanation.

  • @axeman2638
    @axeman2638 4 года назад +13

    You've got a really nice knack from explaining things clearly in simple and straight forward language.
    Thanks very much for you tutorials. Great work.

    • @CodersTape
      @CodersTape  4 года назад +2

      Thanks

    • @axeman2638
      @axeman2638 4 года назад +3

      @@CodersTape ,Thank you, I've been following your Laravel tutorial series, I think it's better than the laracasts tbh.
      Better structure and logical flow from concept to concept and more clearly explained. The laravel documentation is pretty opaque as well and I've not found it of as much help as your stuff. Cheers, keep it up.

  • @arvindbhardwaj3154
    @arvindbhardwaj3154 3 года назад +1

    This is free gold available for everyone.
    Thanks man!!

  • @nikhildhakal3727
    @nikhildhakal3727 4 года назад

    Really well explained video. Just the thing I needed for advanced laravel. Thanks

  • @drakephillips7613
    @drakephillips7613 4 года назад

    clean explanations mate. very easy to understand. thanks.

  • @dopplereffect7325
    @dopplereffect7325 4 года назад +4

    Please I want to thank you for all the tutorials you have put on RUclips ,the way you explain is great. What you put here is the best of all I have had before. Udemy courses cost a lot in my currency ,having this kind of content here for free I what I can't describe, thanks personally you been of great help to me ,keep going ahead

  • @veekly72
    @veekly72 2 года назад

    Nice coaching. thank you. you make it easier for me I was stuck in these relations.

  • @codeology1
    @codeology1 4 года назад +1

    Amazing Tips ... Master of laravel

  • @YusnielBrocard
    @YusnielBrocard 4 года назад

    @Coder's Tape your videos are awesome!!!

  • @Ibenyeugbala
    @Ibenyeugbala Год назад

    Thanks for the clear explanation

  • @deepakthapa9528
    @deepakthapa9528 3 года назад

    Very useful...and practical.

  • @pembatamang5716
    @pembatamang5716 4 года назад

    Wow..thanks for the clear explanation

  • @adam192021
    @adam192021 4 года назад +1

    The BEST as always!

  • @2509killer
    @2509killer 4 года назад

    Sehr verständlich und praktisch erklärt! 👍

  • @rahulxcr
    @rahulxcr Год назад

    Thanks. This is really awesome.

  • @alisleem1626
    @alisleem1626 3 года назад +1

    Thanks Alot , You are really one of my favorites code mentors if not the best. i never understand topics comprehensibly except from u. i am really thankful for ur existence and efforts please keep going . I hope just one more thing i really wanna follow u doing a big project applying many concepts of what u teach using laravel 8 . Hope u will consider that in near future and thanks in advance. Love From Egypt ))

  • @UdanaUdayanga
    @UdanaUdayanga 4 года назад

    please continue this amazing channel. we miss you very much

  • @milad5554
    @milad5554 4 года назад

    That was exactly what i wanted today ! Thanks

  • @sergiovalera3227
    @sergiovalera3227 4 года назад

    You’re simply the best.

  • @SuperBatiskaf
    @SuperBatiskaf 4 года назад

    Victor, you are the best lector - nothing more, everything in the case

  • @rudestewing
    @rudestewing 4 года назад

    Thank you. it's really helpful.

  • @orangecode1902
    @orangecode1902 4 года назад +13

    this Guy Deserve Hundred Million Subscribers you are Awesome Love from Pakistan

  • @anchalpandey9074
    @anchalpandey9074 4 года назад

    I'm just in love love with your channel 💓💓💓you post the moooost valuable content that no other channel post Ur amazing 🙇 💙💙💙

  • @badralwattar5799
    @badralwattar5799 3 года назад

    thank you man, you are the best

  • @asada4297
    @asada4297 2 года назад

    amazing tutorial explain really well thank you Sir,

  • @hasim.infotechsolz
    @hasim.infotechsolz 2 года назад

    Really helpful! ❤️

  • @acedecastro83
    @acedecastro83 4 года назад +2

    The best teacher, as always! I hope you could also make a tutorial on how you implement table pagination (or a datatable in that case) in Vue.js with data (JSON) coming from Laravel as the backend. Thank you for all your work/content.
    Also, I just bought your first course in Udemy. I hope you publish more courses soon :)

  • @rahafmoute4781
    @rahafmoute4781 10 месяцев назад

    Thanks very very match its the most useful course i have ever been seen, I hope to add written english sentences of your speaking to can strangers understand more

  • @user-sg8op9gi3v
    @user-sg8op9gi3v 4 года назад

    thank you for the videos !!! I appreciate you so much from japan!!! your videos help me out so much thank you :)

  • @lionelguaregua820
    @lionelguaregua820 3 года назад

    Great content Bro, I have a lot of time without use this kind of relation, and i forgot the uses cases for it. Thanks, you have my sub

  • @mmtrrz
    @mmtrrz 3 года назад

    I just love this intro music 😍

  • @TH3BADRO
    @TH3BADRO 4 года назад

    Great tutorial. Thank you!

  • @Hipocondriax
    @Hipocondriax 4 года назад +2

    I'm here, tnx!

  • @mirzawajid7823
    @mirzawajid7823 2 года назад

    Very well explained! Love from Pakistan.........

  • @alexandrutrandafir8683
    @alexandrutrandafir8683 4 года назад

    Great video!

  • @robbradley1337
    @robbradley1337 4 года назад +4

    Liked, then watched.

  • @niruddhaRoy
    @niruddhaRoy 4 года назад

    I am thinking that how could you describe the deeping digger terms of laravel so easily, You rock man. Looking more from you....

  • @muhammedmusthafa6501
    @muhammedmusthafa6501 3 года назад

    woow ,nice tutorial man

  • @santiagos4290
    @santiagos4290 3 года назад

    Very clear ;)

  • @afsanehshamsi
    @afsanehshamsi 4 года назад

    that's great.thanks a lot.

  • @JiteshDhamaniya
    @JiteshDhamaniya 4 года назад

    You are a hell of teacher mate. kudos to your efforts. on side note - in this tutorial you said "able" as in imageable is reserved and you must use it, which I believe is not the case. you can really use any name as far as you using same function name in morph model. Like If you using nice as function name for returning return $this->morphTo(); you can then use column name accordingly like nice_id and nice_type and this would work too.
    public function nice()
    {
    return $this->morphTo();
    }
    and then you use nice_type and nice_id, in place of imageable_type and imageable_id.

  • @feranmiafrica9528
    @feranmiafrica9528 4 года назад +3

    Just when I've thought I've know all in laravel this came up.. Victor thank you for your efforts in making us how we are today... May you continue to grow in knowledge, wealth and in good health 😍 like if you love VICTOR

  • @asifsarfraz2994
    @asifsarfraz2994 4 года назад +1

    thank you so much for your work.please make a video on add to cart and add to wishlist topic

  • @numenor21
    @numenor21 4 года назад

    Hey bro, thanks total. Love from venezuela

  • @AMoktar
    @AMoktar Год назад

    Thanks bro, ❤

  • @toshikverma8606
    @toshikverma8606 2 года назад

    i can like this 100 times

  • @christophrumpel
    @christophrumpel 4 года назад

    Great video 👍

  • @omiorangsha665
    @omiorangsha665 4 года назад +2

    we are waiting for full course of it

  • @mel-182
    @mel-182 3 года назад +1

    I always come back for reference here lol

  • @asditaprasetya
    @asditaprasetya 4 года назад +1

    Wow thanks

  • @asdasdasdasdasdas441
    @asdasdasdasdasdas441 4 года назад

    THE MAN of youtube killing it totally best teacher around

  • @jayedkhan1903
    @jayedkhan1903 4 года назад

    Your video quality really good. I love your all video. Please make a video about deployment on shared hosting. And how to process those jobs. Its really important couldn't find any solution

  • @RecklessCoder
    @RecklessCoder 4 года назад +2

    Great Video! Only thing I'm missing is the Relation::morphMap which can be configured in the boot method of the AppServiceProvider. That way the namespaces won't show up in the database like 'App\\User' but for instance as 'user'. That way, when a model gets moved to another namespace you don't have to write migrations, but just change it namespace in the AppServiceProvider.

    • @CodersTape
      @CodersTape  4 года назад

      That's a good point but to be honest I have never had to move a model from their original namespace. Did you have a need to move a model's namespace in a project?

    • @RecklessCoder
      @RecklessCoder 4 года назад +2

      Coder's Tape yes. Currently I’m working on very large projects. Very often we move models from the models-namescape to modules where they belong. The morphMap then comes in handy

    • @CodersTape
      @CodersTape  4 года назад

      @@RecklessCoder that sounds like a great use case.

  • @ahmedwaqar1588
    @ahmedwaqar1588 4 года назад

    Oh man, you are so good at coding :)

  • @minpolik
    @minpolik 4 года назад +1

    There's a ->morpths() method you can use in migrations to create both columns and index them

  • @konstruktion
    @konstruktion 4 года назад

    Please release more examples, like combine with controller, view and so. :)

  • @umerfarooqchattha5685
    @umerfarooqchattha5685 4 года назад

    Thanks

  • @gazorbpazorbian
    @gazorbpazorbian 4 года назад

    Dude, your videos are awesome. To improve on your channel you should use video cards and reference your older videos to this one.

  • @dardi71
    @dardi71 4 года назад +27

    unbelievable , how can you code without doing any mistake ???? .... keep going you are the best!

    • @ProgrammingwithPeter
      @ProgrammingwithPeter 4 года назад +1

      he scripted before and maybe done this at least once(or not) depending of how complex is the concept. I don't like that personally but he explains so well the concepts, a lot bettern than me, but i don't script anything.

    • @hieunguyenac4675
      @hieunguyenac4675 4 года назад +2

      ​@@ProgrammingwithPeter yes, he saved a lot of time for watchers, you should learn about this, just personal opinion 😁

    • @ProgrammingwithPeter
      @ProgrammingwithPeter 4 года назад +1

      @@hieunguyenac4675 I know that he saved a lot of time for the viewers, but i just don't like this style, i always tried to find someone who builds real projects, even if it takes a lot more time, i can learn more and see the flow of developing, that's why i'm doing it right now myself. But, there are more people that prefer scripted . It's not my style. But again, I'm doing a different thing, he teaches you concepts, i build projects

    • @linguapharm
      @linguapharm 4 года назад

      Yes! Keep going plz, Professional coders don't do mistakes!
      And YES! he is the best.

    • @AmeerulIslam
      @AmeerulIslam 4 года назад

      @@ProgrammingwithPeter he builds projects too

  • @graceresourcecentre1200
    @graceresourcecentre1200 4 года назад

    Thank you for this tutorial , just follow-up question this type of relationship is reliable enough? vs the common relationship practice ?

  • @VadimBesedin
    @VadimBesedin 3 года назад +2

    As alternative, we can have an "image_id" in each of the tables that require an image (Users, Posts, etc)

    • @hamzaaslam697
      @hamzaaslam697 3 года назад

      i was also thinking one thing with polymorphic concept i think this DB can't be used with any other language .Please correct me if i am wrong

    • @mohamedshuaau632
      @mohamedshuaau632 3 года назад

      @@hamzaaslam697 technically it can be used. Polymorphic can be implemented yourself

  • @sumitwadhwa8823
    @sumitwadhwa8823 4 года назад

    excellent video. btw, performance-wise, what is more suggestible as the application grows: polymorphic or multiple association tables?

  • @Patrickdaawsome
    @Patrickdaawsome 4 года назад

    Do you have a suggestion on keeping order of images of a One-to-Many relationship?
    Let's say a post usually has a header and footer image. Would you add an incrementing integer column and use code to check it 1 or 2 (like an enum) or would you have a better way to implement this?

  • @SinghatehAlagie
    @SinghatehAlagie 4 года назад

    Mistake is the key of understanding when ever you did mistake in things you will understand that more than the others, that’s why every programmer should learn how to solve mistakes which in the language call debugging. And I am a programmer as well but I love to do some mistakes when coding just to disturb my brain 🧠

  • @milospetkovic9927
    @milospetkovic9927 4 года назад

    Great video/tutorial! I have a question regarding a database query performance. The database column "imageable_type" can't be used as foreign key to an appropriate table because it's used for different models. How it will work in case of many database records when foreign key/index is missing? Is it better to have a separate image table for each model in that case?

  • @SabinSipai
    @SabinSipai 4 года назад

    first of all thank you for explaining so beautifully.
    Can i ask how do you fetch the data according to tags?
    i.e. show video according to tags and show post according to same tag?
    Thank you for making this video

  • @hurlimanjumamuratova2425
    @hurlimanjumamuratova2425 Год назад

    Good day, you rock!!!
    I fell in love with your coding environment, your font, your background && code colors...
    Could you please tell me what do you use for them?

  • @ripon59
    @ripon59 9 месяцев назад

    Sir, your explanation is really pro level & easy to understand. I just have one question about larage amount of data set. Like social media type platform. Do you prefer/mean , is it good practice for the large amount of data set ?

  • @kisstamas6675
    @kisstamas6675 3 года назад

    hi!
    thank you for that video it is awesome! I have some question: What if that morph tables (comments, images, tags.) contains a lot of records? Does the queries will be run slowly?
    Thanks

  • @SethSetiadha
    @SethSetiadha 2 года назад

    When is the best time kr what case is best practice to use polymorphic?

  • @ronssijei
    @ronssijei 4 года назад

    What about creating a history of user's payments and visitor's visits?
    Is the morphing a right way to do it?

  • @christiansenmarcus
    @christiansenmarcus 4 года назад

    How would you do the inverse and query all tags that belong to a specific model?

  • @GurvinderSingh-bz9ys
    @GurvinderSingh-bz9ys 4 года назад +1

    Can you please guide and build a similar video on the business model of "User", "Address" and "Company" tables. Scenario here is that 1. an address can belong to a user and at the same time belongs to a Company, 2. a company can have many branch address and 3. a user can have many billing address (like an amazons many shipping address).
    In an market place there are many user so a users can be a vender with business address and user can have an non-business address who does not belong to a company and is a buyer in that marketplace. Requesting you to please structure it.
    As this is three way relationship explanation needed.
    I believe this video will be very help full to me and to many others. !!!!!

  • @mememedia4788
    @mememedia4788 4 года назад

    Hi, What's the best way to create custom functions/helpers/library in Laravel?. Where can I write codes for reusable functions such as SMS notifications and other API calls to use in multiple controllers. If possible please make a video about it.

  • @delita0057
    @delita0057 4 года назад

    what does it mean "taggable" in the second parameter

  • @SaranshDhingra
    @SaranshDhingra 4 года назад

    Hi! Great Videos :)
    Can you also include a video related to "Creating a custom queue driver", like instead of using DB/SQS/RabbitMQ we use filesystem or something else.
    I have a use case that I need to create one using STOMP from Amazon Mq, but there is no proper documentation on how to create one. Not even a package that works properly.

  • @mundix1
    @mundix1 3 года назад

    hi, how i can verify if for example relation User -> Image, hasImage(Image $image) ? to check before assign again ?

  • @swealthathit2367
    @swealthathit2367 4 года назад

    How can I set up the PhpStorm(theme) like you? Thank you for sharing.

    • @CodersTape
      @CodersTape  4 года назад +2

      The theme is Material Theme Darker

  • @secwriteups
    @secwriteups 4 года назад

    How do you link comments to users in this case ? And, is it possible to make nested comments with this system ?

  • @ademolai9297
    @ademolai9297 4 года назад

    taggable_id remains 1 and unchanged. What's it supposed to be used for ?

  • @andersonmartins3862
    @andersonmartins3862 4 года назад

    Congratulations on the great video!
    How do I get relationship data using ELOQUENT in CONTROLLER?

    • @CodersTape
      @CodersTape  4 года назад +1

      Exactly the same way. Just fetch the record and grab its relationship

    • @andersonmartins3862
      @andersonmartins3862 4 года назад

      @@CodersTape
      Thanks! It works.

  • @vahidabedi9534
    @vahidabedi9534 3 года назад

    Tnx for your great videos. I have one question. What is the advantage of using polymorphism over using the scenario below:
    images table:
    -post_id
    -user_id
    ...
    (and we fill just one of the id columns based on use case)

    • @stevenstraker5105
      @stevenstraker5105 2 года назад

      This is another way of doing it, however, this requires specifying a column for individual relation. Polymorphism allows for dynamic relationships, so the database doesn't require changing each time a a new relationship type is added

  • @codingstuff8305
    @codingstuff8305 4 года назад

    Hi Victor. Just a question for being sure... If my models are in a dedicate folder name Models for example do I have to put the full name space of a relationship declaration?

    • @CodersTape
      @CodersTape  4 года назад +1

      Yes. Or you’ll have to import the class up top with a use statement.

    • @codingstuff8305
      @codingstuff8305 4 года назад

      @@CodersTape OK thanks a lot!!

  • @patrickgomes2261
    @patrickgomes2261 3 года назад

    I think having different tables when you have a big website would be better to maximize the time... Imagine searching in a table with comments from posts, videos and other things all together... Of course you can take based on the type but even though I think it would take more time than a separated table

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 4 года назад

    Hello sir, For creating the task is done, but how to update this existing records in polymorphic.

  • @tothebone4613
    @tothebone4613 4 года назад

    is there any course from you to create one page wih multiple crud many to many relation ship, its like 1 page profile to add lot of function such as add document add position add assignment etc,

  • @jayantrawat5961
    @jayantrawat5961 3 года назад

    What if I want to upload multiple images for a single post. Like one for Thumbnails and another for the gallery?

  • @mahmudrafid3910
    @mahmudrafid3910 4 года назад

    Please post new video. Eagerly waiting.

  • @josibee
    @josibee Год назад

    At 8:25, if you run $user->image()->create(['url' = > 'profile.jpg']); you will have more images for the user. How do you make a constraint that no record should be created for the user if one already exists?

  • @chumarosawa
    @chumarosawa 4 года назад

    Excelents videos Victor, I have a question a litle bit diferent, how to handle the laravel version upgrade in your app?, suposse you have large app maked in laravel 5.5 and now you want to use laravel´s version 6

    • @CodersTape
      @CodersTape  4 года назад

      When upgrading from version to version, you will need to follow each guide and make the necessary changes from 5.5 to 5.6 and then from 5.6 to 5.7 and so on. There’s also a service called Laravel Shift which does the upgrade pretty automatic for you but it costs money. Might be worth looking into it.

  • @muhammadfahad3483
    @muhammadfahad3483 3 года назад

    So if 2 tables is related to one table, we create a polymorphic relationship right?

  • @PunxTV123
    @PunxTV123 4 года назад

    what is the difference putting the image column in POST? is it faster there than creating new table.

    • @CodersTape
      @CodersTape  4 года назад

      I’m not following your question. Can you elaborate?

    • @PunxTV123
      @PunxTV123 4 года назад

      @@CodersTape I mean there is image column in posts table, and the data are url of images. so every query of user/posts need to left join right?

  • @mariaangeles5798
    @mariaangeles5798 4 года назад

    Hello, how are you, could you give an example of how to get api resource with polymorphic relationships. for example: get Post with the comments and image

  • @ShibbirAhmedRaihan
    @ShibbirAhmedRaihan 4 года назад

    First of all, Thanks for your awesome video. But What about if user delete model then how OnUpdate or OnDelete Cascase work?

    • @CodersTape
      @CodersTape  4 года назад +1

      You’d need to set those constraints at the database level.

    • @ShibbirAhmedRaihan
      @ShibbirAhmedRaihan 4 года назад

      @@CodersTapeThanks for your reply.
      Can you explain this? or can you make a tutorial about this?

    • @CodersTape
      @CodersTape  4 года назад

      @@ShibbirAhmedRaihan I'll make sure to add it when we revisit the topic for Laravel 6 Beginner series.

    • @ShibbirAhmedRaihan
      @ShibbirAhmedRaihan 4 года назад

      @@CodersTape Okay Sir

  • @gevorgnikoghosyan7252
    @gevorgnikoghosyan7252 4 года назад +1

    excuse me for a stupid question)) this awesome thing works only on --v 6? i have project 5.7 but damn i want to do that way :D

    • @CodersTape
      @CodersTape  4 года назад +1

      Gevorg Nikoghosyan 100% works in Laravel 5.7. This is not new to L6

    • @gevorgnikoghosyan7252
      @gevorgnikoghosyan7252 4 года назад

      @@CodersTape thanks :) by the way you are the best in explaining things) waiting for more advanced topics ) youre helping a lot !