Laravel 6 Advanced - e3 - Polymorphic Relationships

  Рет қаралды 75,303

Coder's Tape

Coder's Tape

Күн бұрын

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
@arvindbhardwaj3154
@arvindbhardwaj3154 3 жыл бұрын
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
@colinrdixon
@colinrdixon Жыл бұрын
puts it all into perspective!! super appreciate you for this video.
@coolcha
@coolcha 4 жыл бұрын
This video was so nice. It made such a complex topic so much simpler to follow and with examples.
@AwakeningofAI
@AwakeningofAI 4 жыл бұрын
clean explanations mate. very easy to understand. thanks.
@YusnielBrocard
@YusnielBrocard 4 жыл бұрын
@Coder's Tape your videos are awesome!!!
@lysokkong5826
@lysokkong5826 4 жыл бұрын
Crystal clear explanation.
@adam192021
@adam192021 4 жыл бұрын
The BEST as always!
@pavanobhan1105
@pavanobhan1105 2 жыл бұрын
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.
@Chmelewsky
@Chmelewsky 2 жыл бұрын
this is one of the best laravel tutorials i've seen. subscribed!
@veekly72
@veekly72 2 жыл бұрын
Nice coaching. thank you. you make it easier for me I was stuck in these relations.
@JackbearAmine
@JackbearAmine 4 жыл бұрын
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.
@Ibenyeugbala
@Ibenyeugbala Жыл бұрын
Thanks for the clear explanation
@2509killer
@2509killer 4 жыл бұрын
Sehr verständlich und praktisch erklärt! 👍
@dopplereffect7325
@dopplereffect7325 4 жыл бұрын
Please I want to thank you for all the tutorials you have put on KZbin ,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
@UdanaUdayanga
@UdanaUdayanga 4 жыл бұрын
please continue this amazing channel. we miss you very much
@deepakthapa9528
@deepakthapa9528 3 жыл бұрын
Very useful...and practical.
@pembatamang5716
@pembatamang5716 4 жыл бұрын
Wow..thanks for the clear explanation
@rahulxcr
@rahulxcr Жыл бұрын
Thanks. This is really awesome.
@alisleem1626
@alisleem1626 3 жыл бұрын
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 ))
@codeology1
@codeology1 4 жыл бұрын
Amazing Tips ... Master of laravel
@milad5554
@milad5554 4 жыл бұрын
That was exactly what i wanted today ! Thanks
@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 🙇 💙💙💙
@CodersTape
@CodersTape 4 жыл бұрын
Thanks!
@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
@rudestewing
@rudestewing 4 жыл бұрын
Thank you. it's really helpful.
@axeman2638
@axeman2638 4 жыл бұрын
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 жыл бұрын
Thanks
@axeman2638
@axeman2638 4 жыл бұрын
@@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.
@hasim.infotechsolz
@hasim.infotechsolz 2 жыл бұрын
Really helpful! ❤️
@badralwattar5799
@badralwattar5799 3 жыл бұрын
thank you man, you are the best
@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 :)
@acedecastro83
@acedecastro83 4 жыл бұрын
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 :)
@SuperBatiskaf
@SuperBatiskaf 4 жыл бұрын
Victor, you are the best lector - nothing more, everything in the case
@CodersTape
@CodersTape 4 жыл бұрын
Thanks
@sergiovalera3227
@sergiovalera3227 4 жыл бұрын
You’re simply the best.
@asada4297
@asada4297 2 жыл бұрын
amazing tutorial explain really well thank you Sir,
@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
@orangecode1902
@orangecode1902 4 жыл бұрын
this Guy Deserve Hundred Million Subscribers you are Awesome Love from Pakistan
@CodersTape
@CodersTape 4 жыл бұрын
Thanks!
@divinealien7620
@divinealien7620 4 жыл бұрын
I agree these videos and codes are so clean RESPECT
@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....
@alexandrutrandafir8683
@alexandrutrandafir8683 4 жыл бұрын
Great video!
@Hipocondriax
@Hipocondriax 4 жыл бұрын
I'm here, tnx!
@mmtrrz
@mmtrrz 3 жыл бұрын
I just love this intro music 😍
@TH3BADRO
@TH3BADRO 4 жыл бұрын
Great tutorial. Thank you!
@santiagos4290
@santiagos4290 3 жыл бұрын
Very clear ;)
@afsanehshamsi
@afsanehshamsi 4 жыл бұрын
that's great.thanks a lot.
@asifsarfraz2994
@asifsarfraz2994 4 жыл бұрын
thank you so much for your work.please make a video on add to cart and add to wishlist topic
@robbradley1337
@robbradley1337 4 жыл бұрын
Liked, then watched.
@feranmiafrica9528
@feranmiafrica9528 4 жыл бұрын
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
@CodersTape
@CodersTape 4 жыл бұрын
Thanks! All the best!
@muhammedmusthafa6501
@muhammedmusthafa6501 3 жыл бұрын
woow ,nice tutorial man
@AMoktar
@AMoktar Жыл бұрын
Thanks bro, ❤
@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.
@asditaprasetya
@asditaprasetya 4 жыл бұрын
Wow thanks
@omiorangsha665
@omiorangsha665 4 жыл бұрын
we are waiting for full course of it
@toshikverma8606
@toshikverma8606 2 жыл бұрын
i can like this 100 times
@mirzawajid7823
@mirzawajid7823 2 жыл бұрын
Very well explained! Love from Pakistan.........
@christophrumpel
@christophrumpel 4 жыл бұрын
Great video 👍
@CodersTape
@CodersTape 4 жыл бұрын
Thanks Christoph
@numenor21
@numenor21 4 жыл бұрын
Hey bro, thanks total. Love from venezuela
@CodersTape
@CodersTape 4 жыл бұрын
Dale. Gracias.
@umerfarooqchattha5685
@umerfarooqchattha5685 4 жыл бұрын
Thanks
@ahmedwaqar1588
@ahmedwaqar1588 4 жыл бұрын
Oh man, you are so good at coding :)
@mel-182
@mel-182 3 жыл бұрын
I always come back for reference here lol
@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 жыл бұрын
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 жыл бұрын
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.
@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.
@konstruktion
@konstruktion 4 жыл бұрын
Please release more examples, like combine with controller, view and so. :)
@minpolik
@minpolik 4 жыл бұрын
There's a ->morpths() method you can use in migrations to create both columns and index them
@CodersTape
@CodersTape 4 жыл бұрын
Yup
@asdasdasdasdasdas441
@asdasdasdasdasdas441 4 жыл бұрын
THE MAN of youtube killing it totally best teacher around
@CodersTape
@CodersTape 4 жыл бұрын
Thank you
@dardi71
@dardi71 4 жыл бұрын
unbelievable , how can you code without doing any mistake ???? .... keep going you are the best!
@ProgrammingwithPeter
@ProgrammingwithPeter 4 жыл бұрын
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 жыл бұрын
​@@ProgrammingwithPeter yes, he saved a lot of time for watchers, you should learn about this, just personal opinion 😁
@ProgrammingwithPeter
@ProgrammingwithPeter 4 жыл бұрын
@@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 ?
@sumitwadhwa8823
@sumitwadhwa8823 4 жыл бұрын
excellent video. btw, performance-wise, what is more suggestible as the application grows: polymorphic or multiple association tables?
@VadimBesedin
@VadimBesedin 3 жыл бұрын
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
@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?
@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?
@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?
@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
@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
@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 🧠
@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 ?
@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.
@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.
@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?
@SethSetiadha
@SethSetiadha 2 жыл бұрын
When is the best time kr what case is best practice to use polymorphic?
@christiansenmarcus
@christiansenmarcus 4 жыл бұрын
How would you do the inverse and query all tags that belong to a specific model?
@GurvinderSingh-bz9ys
@GurvinderSingh-bz9ys 4 жыл бұрын
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. !!!!!
@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 жыл бұрын
Yes. Or you’ll have to import the class up top with a use statement.
@codingstuff8305
@codingstuff8305 4 жыл бұрын
@@CodersTape OK thanks a lot!!
@secwriteups
@secwriteups 4 жыл бұрын
How do you link comments to users in this case ? And, is it possible to make nested comments with this system ?
@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,
@delita0057
@delita0057 4 жыл бұрын
what does it mean "taggable" in the second parameter
@mundix1
@mundix1 3 жыл бұрын
hi, how i can verify if for example relation User -> Image, hasImage(Image $image) ? to check before assign again ?
@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
@ademolai9297
@ademolai9297 4 жыл бұрын
taggable_id remains 1 and unchanged. What's it supposed to be used for ?
@jayantrawat5961
@jayantrawat5961 3 жыл бұрын
What if I want to upload multiple images for a single post. Like one for Thumbnails and another for the gallery?
@andersonmartins3862
@andersonmartins3862 4 жыл бұрын
Congratulations on the great video! How do I get relationship data using ELOQUENT in CONTROLLER?
@CodersTape
@CodersTape 4 жыл бұрын
Exactly the same way. Just fetch the record and grab its relationship
@andersonmartins3862
@andersonmartins3862 4 жыл бұрын
@@CodersTape Thanks! It works.
@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.
@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?
@neerajsinghtangariya2587
@neerajsinghtangariya2587 4 жыл бұрын
Hello sir, For creating the task is done, but how to update this existing records in polymorphic.
@ehSamurai3483
@ehSamurai3483 3 жыл бұрын
So if 2 tables is related to one table, we create a polymorphic relationship 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
@swealthathit2367
@swealthathit2367 4 жыл бұрын
How can I set up the PhpStorm(theme) like you? Thank you for sharing.
@CodersTape
@CodersTape 4 жыл бұрын
The theme is Material Theme Darker
@md.imrulhasan8757
@md.imrulhasan8757 3 жыл бұрын
In 8:50 You said, "So this image can not belong to more than one 'User'.". What does it mean? Is it mean a profile picture with a unique URL can not be used by more than a user? I query it. But it creates a unique image URL with two users. Do you clear me out?
@mahmudrafid3910
@mahmudrafid3910 4 жыл бұрын
Please post new video. Eagerly waiting.
@gevorgnikoghosyan7252
@gevorgnikoghosyan7252 4 жыл бұрын
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 жыл бұрын
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 !
@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
@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?
Laravel 6 Advanced - e4 - Facades
24:33
Coder's Tape
Рет қаралды 61 М.
Eloquent Polymorphic Relations: Properly Explained
9:56
Laravel Daily
Рет қаралды 40 М.
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 546 М.
ТАМАЕВ УНИЧТОЖИЛ CLS ВЕНГАЛБИ! Конфликт с Ахмедом?!
25:37
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 104 МЛН
Laravel: BelongsTo vs Polymorphic? Let's Test!
14:09
Laravel Daily
Рет қаралды 26 М.
Laravel 6 Advanced - e7 - Repository Pattern
23:24
Coder's Tape
Рет қаралды 103 М.
Laravel 6 Advanced - e1 - Service Container
23:27
Coder's Tape
Рет қаралды 272 М.
Laravel Pivot Tables: Simple to Advanced Many-to-Many
12:24
Laravel Daily
Рет қаралды 119 М.
Laravel 6 Advanced - e6 - Pipelines
28:53
Coder's Tape
Рет қаралды 52 М.
5 tips for supercharged Laravel Eloquent queries
16:29
Andrew Schmelyun
Рет қаралды 67 М.
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 546 М.