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

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 65

  • @codewithdary
    @codewithdary  2 ปีที่แล้ว

    LETS CONNECT THROUGH INSTAGRAM.
    instagram.com/codewithdary

  • @FririkurEllefsen
    @FririkurEllefsen 9 หลายเดือนก่อน +1

    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  8 หลายเดือนก่อน

      Yes, it helps a lot!

  • @OurModernWorld
    @OurModernWorld ปีที่แล้ว +1

    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

  • @kemal6039
    @kemal6039 2 ปีที่แล้ว +5

    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  2 ปีที่แล้ว

      Thank you for sharing Kemal

  • @Ahabib2009
    @Ahabib2009 ปีที่แล้ว +1

    Great Dary. Really appreciate

  • @amiralipishdadi
    @amiralipishdadi 11 หลายเดือนก่อน +1

    thank you dary 😍
    very good

    • @codewithdary
      @codewithdary  11 หลายเดือนก่อน

      You're welcome 😊

  • @sirbangalot569
    @sirbangalot569 3 ปีที่แล้ว +2

    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!

  • @william254
    @william254 3 ปีที่แล้ว +1

    Great video as always Dary. Really appreciate

  • @lancespurgeon
    @lancespurgeon 2 ปีที่แล้ว +1

    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?

  • @fabiolisboa2156
    @fabiolisboa2156 3 ปีที่แล้ว +1

    an excelente tutorial bro
    you illuminated my mind thank you so much

  • @agafonovas
    @agafonovas ปีที่แล้ว

    Love your videos man 😮

  • @shafiu283
    @shafiu283 3 ปีที่แล้ว

    I really like coding with Dary

  • @chukwuebukaohaji5285
    @chukwuebukaohaji5285 2 ปีที่แล้ว

    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..

  • @tech-trials
    @tech-trials 3 ปีที่แล้ว +2

    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

  • @peteririogbe3444
    @peteririogbe3444 3 ปีที่แล้ว +1

    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  3 ปีที่แล้ว +1

      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 3 ปีที่แล้ว +1

      @@codewithdary I have already downloaded it. I need more excellent tutorials from you.
      You are making my day so excited

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      Depends on what you want to do with the carModel, but in most cases nope.

  • @Ramziddin_Rustamovv
    @Ramziddin_Rustamovv 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 .....

  • @daffahanz1540
    @daffahanz1540 3 ปีที่แล้ว +2

    Is the 'carModels' in '$car->carModels' a relationship function residing in the Car.php model?

  • @alexpmh
    @alexpmh 3 ปีที่แล้ว +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 :)

  • @mamaddodol3528
    @mamaddodol3528 3 ปีที่แล้ว

    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

  • @JohnSmith-zl8rz
    @JohnSmith-zl8rz 3 ปีที่แล้ว +1

    what's the goal to "protected" the table and the "primary key"?

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว +1

      the property or method can be accessed within the class and by classes derived from that class

  • @rajabhishek2936
    @rajabhishek2936 3 ปีที่แล้ว +1

    Nice video

  • @mariuszdabrowski307
    @mariuszdabrowski307 3 ปีที่แล้ว +1

    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  3 ปีที่แล้ว

      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 3 ปีที่แล้ว

      @@codewithdary in this way i must every time create new user when i want create xyz?

  • @santhoshkumar-sf4bc
    @santhoshkumar-sf4bc 3 ปีที่แล้ว +1

    Hi.., how to add column to table by migration without loss of data???

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว +1

      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

  • @carlfranz6805
    @carlfranz6805 2 ปีที่แล้ว +1

    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!

  • @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

  • @Enol_ww
    @Enol_ww 3 ปีที่แล้ว

    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.

  • @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.

  • @Borma425
    @Borma425 3 ปีที่แล้ว

    what about many to many ?

  • @aldrinedeguzman7652
    @aldrinedeguzman7652 3 ปีที่แล้ว +1

    Dude how to show only one model name?

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว +1

      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 3 ปีที่แล้ว

    The most important part the guy didn't do, that is the insertions.

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว

      That guy has a name (me) and what do you mean insertions?

    • @brenol2177
      @brenol2177 3 ปีที่แล้ว

      @@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  3 ปีที่แล้ว +1

      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 3 ปีที่แล้ว +1

      @@codewithdary thanks for the response :]

    • @codewithdary
      @codewithdary  3 ปีที่แล้ว

      @Breno L no worries buddy :)