Eloquent Polymorphic Relations: Properly Explained

  Рет қаралды 40,478

Laravel Daily

Laravel Daily

5 жыл бұрын

One video from my course "Eloquent: Expert Level": laraveldaily.teachable.com/p/...
Polymorphic relations are one of the most difficult concept to understand for junior developers, and I tried to do it with a real-life example.

Пікірлер: 44
@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.
@kevinnacario359
@kevinnacario359 3 жыл бұрын
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.
@VadimBesedin
@VadimBesedin 3 жыл бұрын
As always - great explanation with examples. Thank you
@reesss4
@reesss4 Жыл бұрын
This is by far the best explanation I have seen! Thank you!
@shafqatalinawaz6218
@shafqatalinawaz6218 2 жыл бұрын
Thanks for sharing. I now understand perfectly how to use polymorphic relationships.
@heitorferreira964
@heitorferreira964 2 жыл бұрын
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.
@Hiltaku
@Hiltaku 3 жыл бұрын
Thanks! Love the example. Makes the concept very easy to understand
@wtalkie
@wtalkie 4 ай бұрын
Great explanation as always. You're the go-to channel for anything laravel-related.
@andywong2244
@andywong2244 Жыл бұрын
i was able to get the concept behind polymorphism at the 1st 3 minutes of your explanation Povilas! you teach very well!
@georgenikou
@georgenikou 4 жыл бұрын
Really well explained, thank you very much for this!
@Egadirov
@Egadirov 5 жыл бұрын
Great example, thanks!
@linaktashifteam1826
@linaktashifteam1826 5 жыл бұрын
very clear explication, thanks
@kmaphane
@kmaphane 10 ай бұрын
Best explanation I found. Thanks a mill
@susanjoshi5948
@susanjoshi5948 4 жыл бұрын
I wish real life relationships were this simple. :D Lit tutorial.
@prianasaputra7583
@prianasaputra7583 11 ай бұрын
Thanks, Now I understand this topic. Thank you sho much.
@rahweekhum9931
@rahweekhum9931 5 жыл бұрын
Thank you for your useful video.
@dedecovasco
@dedecovasco 4 жыл бұрын
Awesome!! Thank you very much
@md.rakibuddinrana3765
@md.rakibuddinrana3765 2 жыл бұрын
Awesome🥰 thank you
@avfoxstudios3226
@avfoxstudios3226 Жыл бұрын
well explained...bravo
@eli-thegreatdiscovery
@eli-thegreatdiscovery 21 күн бұрын
Great video.
@user-wf5jv1me2b
@user-wf5jv1me2b 3 жыл бұрын
!!!!! Thank you very match !
@sofiatopalidi9403
@sofiatopalidi9403 2 жыл бұрын
Thank you :)
@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
@opentech5972
@opentech5972 5 жыл бұрын
That mechanical keyboard sound, satisfying.
@asatbekxalimjonov4005
@asatbekxalimjonov4005 3 жыл бұрын
amazing
@vitaminabe
@vitaminabe 3 жыл бұрын
thank you, very informative!
@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.
@shubhamsahuSD
@shubhamsahuSD 7 ай бұрын
Got it
@ashique12009
@ashique12009 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.
@andywong2244
@andywong2244 Жыл бұрын
well said brother!
@adnanasad4674
@adnanasad4674 2 ай бұрын
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.
@SalmanMemon_Sam
@SalmanMemon_Sam 4 жыл бұрын
best
@WaheedSindhani
@WaheedSindhani 4 жыл бұрын
How do we retrieve all data with relations.
@mikeendsley8453
@mikeendsley8453 5 жыл бұрын
Excellent video… you just saved my butt! Do you have any Udemy courses?
@PovilasKorop
@PovilasKorop 5 жыл бұрын
Thanks Mike. Not on udemy, but on teachable - see laraveldaily.teachable.com
@NMND.
@NMND. 2 жыл бұрын
AAAARGH SO BRIGHT! x_x
@VadimBesedin
@VadimBesedin 3 жыл бұрын
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 3 жыл бұрын
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.
@twentxx
@twentxx 2 жыл бұрын
Thanks very much, but this video not include Factories and Seeders
@unomas9686
@unomas9686 3 жыл бұрын
You are the best teacher ! From russia. putin-juilo
@nahueljj
@nahueljj 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@nahueljj I think it's fine.
Laravel 6 Advanced - e3 - Polymorphic Relationships
21:33
Coder's Tape
Рет қаралды 75 М.
9 Tips for Shorter Laravel Code
10:16
Laravel Daily
Рет қаралды 61 М.
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 37 МЛН
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 4,6 МЛН
Eloquent vs Query Builder vs SQL: Performance Test
5:37
Laravel Daily
Рет қаралды 49 М.
Laravel Pivot Tables: Simple to Advanced Many-to-Many
12:24
Laravel Daily
Рет қаралды 119 М.
The New Way to Define Eloquent Accessors and Mutators
8:38
Laracasts
Рет қаралды 4,3 М.
Laravel: BelongsTo vs Polymorphic? Let's Test!
14:09
Laravel Daily
Рет қаралды 26 М.
Why Don't We Have A Laravel For JavaScript?
12:36
Theo - t3․gg
Рет қаралды 89 М.
Exceptions in Laravel: Why/How to Use and Create Your Own
12:18
Laravel Daily
Рет қаралды 87 М.
5 tips for supercharged Laravel Eloquent queries
16:29
Andrew Schmelyun
Рет қаралды 67 М.
Papai e Bebê sincronizados #maternidade
0:11
Lackto
Рет қаралды 6 МЛН
who is the champion of ludo luck balloon popping race ?
0:59
SS FOOD CHALLENGE
Рет қаралды 56 МЛН
Почаще проводите время с Родителями 🥺❤️
0:51
Dragon Нургелды 🐉
Рет қаралды 671 М.
Qual você NÃO comeria?
0:14
F L U S C O M A N I A
Рет қаралды 14 МЛН