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

Комментарии • 45

  • @codewithdary
    @codewithdary  2 года назад

    LETS CONNECT THROUGH INSTAGRAM.
    instagram.com/codewithdary

  • @user-zm2dn8nn1u
    @user-zm2dn8nn1u 10 месяцев назад

    Awesome sir u r live saver thanks from India

  • @shaquankelly6655
    @shaquankelly6655 2 года назад

    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!

  • @lauragriffiths3332
    @lauragriffiths3332 3 года назад +1

    This has helped me loads, thank you

  • @dacpuspadewi
    @dacpuspadewi 2 года назад +1

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

  • @ramiavrahami8709
    @ramiavrahami8709 3 года назад +3

    Dary, I think some additional part should be added which is talking about attach and sync functions. Great work !!

    • @codewithdary
      @codewithdary  3 года назад +1

      Thanks for the suggestion Rami!

  • @elkhanhamet2561
    @elkhanhamet2561 3 года назад +1

    thank you Dary, appreciate your hard work for us man!!!👍👍👍👏👏👏👏.Stay safe!!!

    • @codewithdary
      @codewithdary  3 года назад

      Thank you, I will Elkhan, you too!

    • @codewithdary
      @codewithdary  3 года назад

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

  • @ttakaew1195
    @ttakaew1195 Год назад +1

    thank you for making it easy for me, i really dumb

    • @codewithdary
      @codewithdary  Год назад

      No dumbs here, just a learning experience :)

  • @MaartenKnolle
    @MaartenKnolle 2 года назад +1

    thank you very much. helped me a lot.

  • @shafiu283
    @shafiu283 2 года назад

    Great work!!!

  • @mr_presley
    @mr_presley 2 года назад +1

    This was a helpful video Thanks!

  • @odilurinkulov7489
    @odilurinkulov7489 3 года назад +1

    Thank you!!!

  • @TheWaqaspuri
    @TheWaqaspuri Год назад

    While making the function in Model, What is the rule for BelongsTo function e.g. will Changing product to product1 works?

  • @linglingzhang8583
    @linglingzhang8583 2 года назад

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

  • @ezzygd2521
    @ezzygd2521 Год назад

    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?

  • @SethSetiadha
    @SethSetiadha Год назад

    I dont see you create pivot table model, so i suppose that one is not necessary?

    • @codewithdary
      @codewithdary  Год назад

      I've just rewatched the video because I thought I was crazy. Look again :)

  • @AnkitPatel-pk1ts
    @AnkitPatel-pk1ts 2 года назад

    in hasonethrough Date was wrong...

  • @auroraapps1853
    @auroraapps1853 2 года назад +1

    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 :(

    • @codewithdary
      @codewithdary  2 года назад +1

      Sorry for that bud. I changed it up for my new tutorials :)

    • @auroraapps1853
      @auroraapps1853 2 года назад

      By the way your way of teaching is nice i like it. 👍

  • @sulaimanmisri9570
    @sulaimanmisri9570 3 года назад +1

    I found this tutorial is more hard to understand compare to other tutorial :(

    • @codewithdary
      @codewithdary  3 года назад +1

      Completely understand you. But that’s because relationships are difficult in Laravel, watch it a couple times and you’ll get used to it.

    • @codewithdary
      @codewithdary  3 года назад +1

      @@carlmenger4964 interesting

    • @marcelrozendaal776
      @marcelrozendaal776 3 года назад

      @@carlmenger4964 I don't understand you're reaction??

  • @rajabhishek2936
    @rajabhishek2936 3 года назад

    Awosem