Eloquent Many To Many Relationship | Laravel For Beginners | Learn Laravel
HTML-код
- Опубликовано: 3 июл 2024
- This video will dive into Eloquent’s Many to Many Relationship in Laravel - Learn one of the most popular PHP frameworks for its advanced features, templating engine, fast commands and security.
📚 New Udemy Course
If you're looking to level up your Laravel skills, my new course "Udemy Migirations, Seeders, Factories, Query Builder, Eloquent & Relationships" is the perfect opportunity. Learn the essential tools and techniques for building robust and scalable web applications with Laravel: www.udemy.com/course/masterin...
📲 Let’s plan a meeting
Plan a (paid) 1-hour meeting on Calendly to do portfolio reviews, code reviews resume reviews or a coaching session for Laravel. Please read the description before booking: calendly.com/codewithdary
💌 Newsletter
Sign up for my free weekly email newsletter: www.newsletter.codewithdary.com
🔥 Resources
- PHP Hosting (10% DISCOUNT): www.hostinger.com/codewithdary
- TikTok: / codewithdary
- Instagram: / codewithdary
- Twitter: / codewithdary
- Blog: blog.codewithdary.com/
- Newsletter: newsletter.codewithdary.com/
- Patreon: www.patreon.com/user?u=30307830
- GitHub: github.com/codewithdary
Want to learn more?
- Courses: / @codewithdary
📋 Table of Content
00:00 - Introduction
01:45 - Many to Many model & migration
04:19 - Insert data in MySQL
06:21 - belongsToMany() relationship
07:00 - Print data in the UI
08:40 - Inverse Many To Many relationship
#laravel #laravel8 #php #manytomany #eloquent
LETS CONNECT THROUGH INSTAGRAM.
instagram.com/codewithdary
Awesome sir u r live saver thanks from India
Followed this tutorial and I think it is great. One thing I will add though (took me a while to figure out what I was doing wrong) is that to access the relationship through an API/Controller you don't call it as a function but a relationship property.
So instead of $pizza->ingredients(); it would be $pizza->ingredients;
Just in case anyone Laravel newbies come across this in the future. Thanks for the tutorial!
Thanks for sharing bud!
This has helped me loads, thank you
Glad it helped
Hi Dary, thanks for the tutorial. and i want to ask some relation case.
for example, i have 4 models which connect 4 tables :
1st model (dupak table):
public function activities()
{
return $this->belongsToMany(Activity::class, 'activity_dupaks', 'dupak_id', 'activity_id');
}
2nd model (activities table):
public function dupak()
{
return $this->belongsToMany(Dupak::class, 'activity_dupaks', 'activity_id', 'dupak_id');
}
public function productionType()
{
return $this->belongsTo(ProductionType::class, 'production_type_id');
}
3rd model (production_types table):
public function activities()
{
return $this->hasMany(Activity::class);
}
public function resultUnit()
{
return $this->belongsTo(ResultUnit::class, 'result_unit_id');
}
4th model (result_unit table):
public function productionTypes()
{
return $this->hasMany(ProductionType::class);
}
the questions is, how to get data from result_unit table, from dupak table collection(->get()) ?
i want to foreach the $dupaks = Dupak::where(....)->get(); in blade, and show some data from result_unit table through $dupaks foreach.
i really clueless for this case. i hope u answer my question :') thankyou^^
Dary, I think some additional part should be added which is talking about attach and sync functions. Great work !!
Thanks for the suggestion Rami!
thank you Dary, appreciate your hard work for us man!!!👍👍👍👏👏👏👏.Stay safe!!!
Thank you, I will Elkhan, you too!
@@carlmenger4964 No you are completely right Carl Menger. I kept your previous racist comment but I delete comments of people that are negative. That also has to do with race obviously...
thank you for making it easy for me, i really dumb
No dumbs here, just a learning experience :)
thank you very much. helped me a lot.
You're welcome!
Great work!!!
Thank you so much 😀
This was a helpful video Thanks!
Glad it was helpful!
Thank you!!!
You are Welcome Odil!
While making the function in Model, What is the rule for BelongsTo function e.g. will Changing product to product1 works?
6:46, if i understood correct, may it should be like all the cars belong to many products, instead of " all the products belongs to specific car".
Don't know if you still reply, but is it safe to call delete on cascade in many to many relations? I still don't understand how that wouldn't result in, say, if you delete a car, then all the products related to it get deleted too? Or are we just deleting the connection in the pivot table in this case?
I dont see you create pivot table model, so i suppose that one is not necessary?
I've just rewatched the video because I thought I was crazy. Look again :)
in hasonethrough Date was wrong...
Good work but : I was watching your course, but left because all videos are linked to previous one's please design in such a way that a novice viewer can easily grasp the concepts. I was watching API development playlist but you didn't teach how to configure msqli to commandline and I was wondering how to do so you was typing commands and fetching data :(
Sorry for that bud. I changed it up for my new tutorials :)
By the way your way of teaching is nice i like it. 👍
I found this tutorial is more hard to understand compare to other tutorial :(
Completely understand you. But that’s because relationships are difficult in Laravel, watch it a couple times and you’ll get used to it.
@@carlmenger4964 interesting
@@carlmenger4964 I don't understand you're reaction??
Awosem