Eloquent One to Many Relationship | Laravel For Beginners | Learn Laravel

  Рет қаралды 41,335

Code With Dary

Code With Dary

3 жыл бұрын

This video will dive into Eloquent’s One 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
#laravel #laravel8 #php #onetomany #eloquent

Пікірлер: 65
@codewithdary
@codewithdary 2 жыл бұрын
LETS CONNECT THROUGH INSTAGRAM. www.Instagram.com/codewithdary
@fabiolisboa2156
@fabiolisboa2156 2 жыл бұрын
an excelente tutorial bro you illuminated my mind thank you so much
@FririkurEllefsen
@FririkurEllefsen 4 ай бұрын
Thanks for the tip about using the ForElse loop and "empty". I will rewrite some of my code and use those instead of numerous IF's
@codewithdary
@codewithdary 4 ай бұрын
Yes, it helps a lot!
@kemal6039
@kemal6039 Жыл бұрын
If you're having "Foreign key constraint is incorrectly formed" error, do these : 1 - On the migration file, change the type of your foreign key to unsignedBigInteger from unsignedInteger 2 - Make sure the table that foreign key belongs, is being migrated before the table(s) with foreign key. You can accomplish this by renaming its migration file, for example change the "2022_" in the start of the name to "2001_"
@codewithdary
@codewithdary Жыл бұрын
Thank you for sharing Kemal
@william254
@william254 2 жыл бұрын
Great video as always Dary. Really appreciate
@codewithdary
@codewithdary 2 жыл бұрын
Thanks again!
@OurModernWorld
@OurModernWorld Жыл бұрын
i think that you are the best tutor ever, i just love your content, your way of explaining stuff is the best, with all do respect to all other tutorial creators.✌
@codewithdary
@codewithdary Жыл бұрын
Thank you so much John, comments like these make my day man
@OurModernWorld
@OurModernWorld Жыл бұрын
@@codewithdary cheers
@Ahabib2009
@Ahabib2009 Жыл бұрын
Great Dary. Really appreciate
@codewithdary
@codewithdary Жыл бұрын
Glad you liked it Ahabib!
@user-ch9qp6dw1q
@user-ch9qp6dw1q 6 ай бұрын
thank you dary 😍 very good
@codewithdary
@codewithdary 6 ай бұрын
You're welcome 😊
@lancespurgeon
@lancespurgeon 2 жыл бұрын
So much easier to understand, thanks. To build on your example of cars and car_model how would you automatically insert default 'name' with lastid create from cars table?
@sirbangalot569
@sirbangalot569 3 жыл бұрын
It's funny how I tried looking up adding foreign keys online and would always get an error...them booom💥 I do your tutorial and it works. Good work man, can't thank you enough
@codewithdary
@codewithdary 3 жыл бұрын
Always good to read that! Thank you for your kind words man!
@agafonovas
@agafonovas 9 ай бұрын
Love your videos man 😮
@codewithdary
@codewithdary 9 ай бұрын
Thank you
@tech-trials
@tech-trials 3 жыл бұрын
At the end of this video i used '{{ $model->model_name }}' and it worked for me dunno if thats cuz i used a separate migration for carModels instead of adding it into the cars migration
@codewithdary
@codewithdary 3 жыл бұрын
You can’t access arrays with the access operator [->]. It only applies to objects. But you can use the brackets to access an array. It just depends on how you pull out data from your database. If you var_dump your array, you can see what if it's an array/object/collection
@shafiu283
@shafiu283 3 жыл бұрын
I really like coding with Dary
@codewithdary
@codewithdary 3 жыл бұрын
Thank you Shafiu!
@peteririogbe3444
@peteririogbe3444 2 жыл бұрын
Hello Dary. Thank you for your great tutorial. I enjoy it. Pls can you make a blog that has different categories. I need it
@codewithdary
@codewithdary 2 жыл бұрын
That's very interesting, I'll think about it :) I do got a complete tutorial on how to create a blog if you are interested.
@peteririogbe3444
@peteririogbe3444 2 жыл бұрын
@@codewithdary I have already downloaded it. I need more excellent tutorials from you. You are making my day so excited
@codewithdary
@codewithdary 2 жыл бұрын
Thank you so much Peter, you made my day with your comment! :)
@randomyuber5012
@randomyuber5012 3 жыл бұрын
Hey, lets say we wanna insert to the carModel table, do we have to create the controller for it aswell? Or is there another laravel magic to make this easier? Great tutorial btw!
@codewithdary
@codewithdary 3 жыл бұрын
Depends on what you want to do with the carModel, but in most cases nope.
@shawyarshah231
@shawyarshah231 3 жыл бұрын
Hi Dary thanks for the amazing videos about laravel. I have been facing something I don't know how to write the query in Laravel for it. I have two tables (users & user likes) users has two columns( id, name ) and user_likes has two columns ( user_id, liked_user), how can return all the users in users table except those users that the user has already liked them in Laravel? Please! for example: user 1in users table, liked user number 2 & 4. he can see all the users except user 2 & user 4. and so on for the other users. Please help
@chukwuebukaohaji5285
@chukwuebukaohaji5285 Жыл бұрын
Hello Dary, nice video. I followed everything you did word for word (though different names etc) but I keep getting an error "Invalid argument supplied for foreach()". Please help out..
@mamaddodol3528
@mamaddodol3528 2 жыл бұрын
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'car_models.blueprint_id' in 'where clause' (SQL: select * from `car_models` where `car_models`.`blueprint_id` = 5 and `car_models`.`blueprint_id` is not null) (View: C:\xampp\htdocs\final esources\views\cars\show.blade.php) the blueprint is the car model
@daffahanz1540
@daffahanz1540 3 жыл бұрын
Is the 'carModels' in '$car->carModels' a relationship function residing in the Car.php model?
@codewithdary
@codewithdary 3 жыл бұрын
Yes!
@ramziddinrustamov5221
@ramziddinrustamov5221 2 жыл бұрын
Hi bro , i have queation about this topic , now you insert all data manualy , if I except them from user , how can i insert them automatically in the controller . For example post's comment should only be equalto post which is blongs to when user commeted it , it should post automatically in comments table in the column of post_id .... Please answer .....
@rajabhishek2936
@rajabhishek2936 3 жыл бұрын
Nice video
@codewithdary
@codewithdary 3 жыл бұрын
Very nice
@JohnSmith-zl8rz
@JohnSmith-zl8rz 3 жыл бұрын
what's the goal to "protected" the table and the "primary key"?
@codewithdary
@codewithdary 3 жыл бұрын
the property or method can be accessed within the class and by classes derived from that class
@Enol_ww
@Enol_ww 2 жыл бұрын
Hey guys ! I have a question about the tables, basiclly I have a table let's say its about countries.... to insert the name of the country and population, and i also have a table that has more detail about that specific country (president,size). Here is the problem, i made a form to insert the president name and the size in the table with the details, but the foreign key here is the id of the first table...how can i make tell the form or to the controller that i dont want to let anyone to insert the id, and also to let laravel know that the id of the countri is in the url and i dont have to insert it i hope you guys understend, also... sorry for my bad english.
@mariuszdabrowski307
@mariuszdabrowski307 2 жыл бұрын
what if I want to create a new car model with the form. I have to get car_id from somewhere. my idea is to create a private variable in the controller. I set its value in the store (id) method but if I check its value in another method I wrote storeModel (). then its value is null. help please
@codewithdary
@codewithdary 2 жыл бұрын
One way of inserting related table is using relations as: $user = User::create($user_inputs); $xyz = $user->xyz()->create($xyz_inputs); It will automatically fills the user_id in the xyz table.
@mariuszdabrowski307
@mariuszdabrowski307 2 жыл бұрын
@@codewithdary in this way i must every time create new user when i want create xyz?
@santhoshkumar-sf4bc
@santhoshkumar-sf4bc 3 жыл бұрын
Hi.., how to add column to table by migration without loss of data???
@codewithdary
@codewithdary 3 жыл бұрын
Read through this link (Scroll down a bit): devdojo.com/bobbyiliev/how-to-add-a-new-column-to-an-existing-table-in-a-laravel-migration
@alexpmh
@alexpmh 3 жыл бұрын
Hello! You described one to many relationship, so why the title is 'many to many'?
@codewithdary
@codewithdary 3 жыл бұрын
Oh hell, you are completely right. Changed it! My bad :)
@b1olenyleny449
@b1olenyleny449 3 жыл бұрын
Hello, nice video, i wanted to ask you, if you could make a video how to synchronize data from checkboxes to database (i have issue when i want to insert an array of values into database from checkboxes, i want to automatically delete the unchecked checkboxes values from database) i was trying to search for it but couldnt find any solution, thank you for reading this.
@codewithdary
@codewithdary 3 жыл бұрын
Thanks for the idea!
@carlfranz6805
@carlfranz6805 2 жыл бұрын
Um. How do we get to the 'show' function? I keep getting a 404 not found. [edit] Never mind, fixed it, although I didn't figured it out (this is, I've no idea how I fixed it). I'm getting better at debugging this mess, I guess.
@codewithdary
@codewithdary 2 жыл бұрын
Keep working on it, debugging is such an important topic when it comes to coding!
@Borma425
@Borma425 2 жыл бұрын
what about many to many ?
@aldrinedeguzman7652
@aldrinedeguzman7652 3 жыл бұрын
Dude how to show only one model name?
@codewithdary
@codewithdary 3 жыл бұрын
Do you mean the one to one relationship?
@aldrinedeguzman7652
@aldrinedeguzman7652 3 жыл бұрын
@@codewithdary in your video you show a1 a3 a5, how to make only one will show?
@brenol2177
@brenol2177 2 жыл бұрын
The most important part the guy didn't do, that is the insertions.
@codewithdary
@codewithdary 2 жыл бұрын
That guy has a name (me) and what do you mean insertions?
@brenol2177
@brenol2177 2 жыл бұрын
@@codewithdary Sorry didn't mean to offend. I mean the part about how to use laravel to insert the data with relations instead of adding it manually with mysql.
@codewithdary
@codewithdary 2 жыл бұрын
Oh no I'm sorry haha I like to joke around here, sometimes it sounds a bit serious! Ah yeah. That's also a part of the one to many relationship, you are right! :)
@brenol2177
@brenol2177 2 жыл бұрын
@@codewithdary thanks for the response :]
@codewithdary
@codewithdary 2 жыл бұрын
@Breno L no worries buddy :)
Introduction To Eloquent | Laravel For Beginners | Learn Laravel
45:20
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 79 МЛН
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 4,5 МЛН
My little bro is funny😁  @artur-boy
00:18
Andrey Grechka
Рет қаралды 13 МЛН
Laravel Eloquent: Deeper Relationships with One Query
10:37
Laravel Daily
Рет қаралды 137 М.
Laravel 10 full course for beginner -  what is eloquent orm
11:05