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?
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.
this is one of the best laravel tutorials i've seen. subscribed!
puts it all into perspective!! super appreciate you for this video.
This video was so nice. It made such a complex topic so much simpler to follow and with examples.
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.
Crystal clear explanation.
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.
Thanks
@@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.
This is free gold available for everyone.
Thanks man!!
Really well explained video. Just the thing I needed for advanced laravel. Thanks
clean explanations mate. very easy to understand. thanks.
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
Nice coaching. thank you. you make it easier for me I was stuck in these relations.
Amazing Tips ... Master of laravel
@Coder's Tape your videos are awesome!!!
Thanks for the clear explanation
Very useful...and practical.
Wow..thanks for the clear explanation
The BEST as always!
Sehr verständlich und praktisch erklärt! 👍
Thanks. This is really awesome.
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 ))
please continue this amazing channel. we miss you very much
That was exactly what i wanted today ! Thanks
You’re simply the best.
Victor, you are the best lector - nothing more, everything in the case
Thanks
Thank you. it's really helpful.
this Guy Deserve Hundred Million Subscribers you are Awesome Love from Pakistan
Thanks!
I agree these videos and codes are so clean
RESPECT
I'm just in love love with your channel 💓💓💓you post the moooost valuable content that no other channel post Ur amazing 🙇 💙💙💙
Thanks!
thank you man, you are the best
amazing tutorial explain really well thank you Sir,
Really helpful! ❤️
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 :)
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
thank you for the videos !!! I appreciate you so much from japan!!! your videos help me out so much thank you :)
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
I just love this intro music 😍
Great tutorial. Thank you!
I'm here, tnx!
Very well explained! Love from Pakistan.........
Great video!
Liked, then watched.
I am thinking that how could you describe the deeping digger terms of laravel so easily, You rock man. Looking more from you....
woow ,nice tutorial man
Very clear ;)
that's great.thanks a lot.
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.
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
Thanks! All the best!
thank you so much for your work.please make a video on add to cart and add to wishlist topic
Hey bro, thanks total. Love from venezuela
Dale. Gracias.
Thanks bro, ❤
i can like this 100 times
Great video 👍
Thanks Christoph
we are waiting for full course of it
I always come back for reference here lol
Wow thanks
THE MAN of youtube killing it totally best teacher around
Thank you
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
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.
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?
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
@@RecklessCoder that sounds like a great use case.
Oh man, you are so good at coding :)
There's a ->morpths() method you can use in migrations to create both columns and index them
Yup
Please release more examples, like combine with controller, view and so. :)
Thanks
Dude, your videos are awesome. To improve on your channel you should use video cards and reference your older videos to this one.
unbelievable , how can you code without doing any mistake ???? .... keep going you are the best!
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.
@@ProgrammingwithPeter yes, he saved a lot of time for watchers, you should learn about this, just personal opinion 😁
@@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
Yes! Keep going plz, Professional coders don't do mistakes!
And YES! he is the best.
@@ProgrammingwithPeter he builds projects too
Thank you for this tutorial , just follow-up question this type of relationship is reliable enough? vs the common relationship practice ?
As alternative, we can have an "image_id" in each of the tables that require an image (Users, Posts, etc)
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
@@hamzaaslam697 technically it can be used. Polymorphic can be implemented yourself
excellent video. btw, performance-wise, what is more suggestible as the application grows: polymorphic or multiple association tables?
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?
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 🧠
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?
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
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?
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 ?
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
When is the best time kr what case is best practice to use polymorphic?
What about creating a history of user's payments and visitor's visits?
Is the morphing a right way to do it?
How would you do the inverse and query all tags that belong to a specific model?
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. !!!!!
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.
what does it mean "taggable" in the second parameter
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.
hi, how i can verify if for example relation User -> Image, hasImage(Image $image) ? to check before assign again ?
How can I set up the PhpStorm(theme) like you? Thank you for sharing.
The theme is Material Theme Darker
How do you link comments to users in this case ? And, is it possible to make nested comments with this system ?
taggable_id remains 1 and unchanged. What's it supposed to be used for ?
Congratulations on the great video!
How do I get relationship data using ELOQUENT in CONTROLLER?
Exactly the same way. Just fetch the record and grab its relationship
@@CodersTape
Thanks! It works.
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)
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
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?
Yes. Or you’ll have to import the class up top with a use statement.
@@CodersTape OK thanks a lot!!
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
Hello sir, For creating the task is done, but how to update this existing records in polymorphic.
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,
What if I want to upload multiple images for a single post. Like one for Thumbnails and another for the gallery?
Please post new video. Eagerly waiting.
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?
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
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.
So if 2 tables is related to one table, we create a polymorphic relationship right?
what is the difference putting the image column in POST? is it faster there than creating new table.
I’m not following your question. Can you elaborate?
@@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?
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
First of all, Thanks for your awesome video. But What about if user delete model then how OnUpdate or OnDelete Cascase work?
You’d need to set those constraints at the database level.
@@CodersTapeThanks for your reply.
Can you explain this? or can you make a tutorial about this?
@@ShibbirAhmedRaihan I'll make sure to add it when we revisit the topic for Laravel 6 Beginner series.
@@CodersTape Okay Sir
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
Gevorg Nikoghosyan 100% works in Laravel 5.7. This is not new to L6
@@CodersTape thanks :) by the way you are the best in explaining things) waiting for more advanced topics ) youre helping a lot !