Laravel Eloquent: Deeper Relationships with One Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 มิ.ย. 2024
  • If you work with a project that has multiple levels of hasMany relationships, you can use hasManyThrough instead, or one of a few packages I will show in this video.
    Official docs on HasManyThrough: laravel.com/docs/8.x/eloquent...
    Packages by Jonas Staudenmeir: github.com/staudenmeir
    My course "Eloquent: Expert Level": laraveldaily.com/course/eloqu...
    My course "Better Eloquent Performance": laraveldaily.com/course/eloqu...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses: laraveldaily.com/courses?mtm_...
    - Laravel QuickAdminPanel: quickadminpanel.com
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: us11.campaign-archive.com/hom...
    - My personal Twitter: / povilaskorop
  • แนวปฏิบัติและการใช้ชีวิต

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

  • @chengkangzai
    @chengkangzai 2 ปีที่แล้ว +66

    This will soon be the one of the most viewed video in this channel 😂 good work

  • @pankajbokdia
    @pankajbokdia 2 ปีที่แล้ว +11

    I cannot thank you enough! Your channel is AMAZING! Thank you for doing what you do!

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

    Soon to by membership this month. Your way of explaining wastes no time and you to the point and so knowledgeable, been watching for year but I need to get into your full courses. Thanks for this, a super help. From cape town, south africa.

  • @0x0456
    @0x0456 ปีที่แล้ว +2

    This is EXACTLY what I needed to see. Thank you so much!

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

    You just earned a new subscriber. Kudos to you. You just showed me exactly what I needed to see

  • @tiagooliveira14
    @tiagooliveira14 2 ปีที่แล้ว +31

    This packages should be in the framework. They're really good.

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

      Anyone can add anything to the framework, it's open-source, so you can try.

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

      Ι was about to say the same.

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

    I literally needed to know this, thank you so much 💓 keep up the great work 💪

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

    Dude! you are awesome, so so accurate!
    You are a good teacher! I love your channel!
    Great work!

  • @salman-804
    @salman-804 2 ปีที่แล้ว +2

    I learnt a lot from this tutorial. Thanks a lot !!

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

    Life saving tip. Life saving package. Congrats to both.

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

    Your videos are always wonderful.

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

    that is what i was searchingfor an hour, thanks alot sir !!!

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

    Your tutorials help a lot... Thanks

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

    Thanks for your laravel daily tips.

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

    Many thanks You are best in yours job ... I cannot thank you enough! Thank you teacher for your trainings!

  • @user-zg1pc6md6y
    @user-zg1pc6md6y 2 ปีที่แล้ว +10

    Большое спасибо) смотрю каждый день. Всегда очень полезно

    • @user-ld1gz1cr1j
      @user-ld1gz1cr1j 2 ปีที่แล้ว

      Реал, не сложно говорит. Прекрасно понятно

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

      Иногда такие вещи показывает что удивляешся

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

    finally the addon is mature enough to use! nice tutorial.

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

    OMG, this is amazing thank you so much!

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

    Problem solving, thanks sir!

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

    Superb Laravel specialized developer of all the time. I like you Sir

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

    Really helpful video. Thank you

  • @md.robelahammed4763
    @md.robelahammed4763 ปีที่แล้ว

    Amazing content. It helps me a lot. Thanks

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

    Thank you so much. It's help me a lot.💝💝

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

    This is what I need!!! Thankyou so muchh for this

  • @vigneswarans13
    @vigneswarans13 3 หลายเดือนก่อน

    Excellent explanation 🎉

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

    This is really great. Love it

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

    Thank you for this video. In real life we need in one query some fields from first level, some from second level, third, etc. But it is another story =)

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

    Thank you.. this help me a lot..

  • @shahosanandaji9894
    @shahosanandaji9894 9 หลายเดือนก่อน

    You are the best, Povilas!

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

    Really good job. Thanks 🙏

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

    Very informative video, thanks.

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

    very very very helpful package thanks !

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

    you are the best ,thanks you for improving my laravel knowledge, i was do stupid things before i see this video 😅

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

    thank you very much for tutorial sir!!

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

    Thank sir , one of the best video

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

    you always provide good content

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

    This is awesome bro......It will help me a lot :)

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

    Wow! that`s really really awesome!

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

    🎉 save the day, thanks a lot

  • @user-rm4zo1mg5o
    @user-rm4zo1mg5o 2 ปีที่แล้ว

    Something done with few lines I have to do with complex sql queries with joins, to do the same on old projects running over laravel 5.2 in my main work. Thank for this video.

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

    this help me a lot, thanks

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

    Thx for the great content

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

    very well. thank you.

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

    Great video💙

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

    awesome, thanks you, please more and more advanced eloquent

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

      I have a full course about advanced eloquent: laraveldaily.teachable.com/p/laravel-eloquent-expert-level

  • @newtonsefa5721
    @newtonsefa5721 9 หลายเดือนก่อน

    Thank you

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

    good work!!!

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

    You are a god to me, thank you so so much

  • @claudiomenares4172
    @claudiomenares4172 3 หลายเดือนก่อน

    Muchas gracias 🤯

  • @YT-Gmailer
    @YT-Gmailer 2 ปีที่แล้ว

    Thank you!

  • @demeja16
    @demeja16 2 ปีที่แล้ว +9

    Очень крутое видео, спасибо за улучшение наших знаний в Laravel:)

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

      ну я хз понял ли он)

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

    This is great thank you.. Could you do a video explaining the different type of relationships and how the database structures should be set up in terms of where foreign keys are, etc?

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

      I have an article: blog.quickadminpanel.com/eloquent-relationships-the-ultimate-guide/
      Also, it's best to read the docs: laravel.com/docs/8.x/eloquent-relationships

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

    very helpfull
    thanks

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

    Pretty helpful!

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

    great, thank you!

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

    Good job!

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

    You are awesome 😍

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

    Brilliant!

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

    Helpful 🙌🖤

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

    Awesome!

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

    thanks a lot

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

    Thanks 🙏

  • @RANJEETKUMAR-wz4dg
    @RANJEETKUMAR-wz4dg 2 ปีที่แล้ว

    amazing thanks

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

    First time seeing video on youtube without dislike button being tick.

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

    thank you very much

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

    Lovely!

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

    The best....Thanks

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

    Thanks 👏

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

    awesome!!

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

    thank you

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

    Best video. 👌

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

    This is cool!!!

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

    thanks

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

    Amazing

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

    Hi Povilas,
    In Eloquent is it possible to join to an arbitrary sql statement? For example, say I have a User model and I want to create a UserStats relationship. However UserStats is not a table, but a sql statement that computes stuff like last_login, number_of_posts, up_votes etc. The only way I've found to do this so far is with a database view that I manage with migrations, but was wondering if this could be done purely in Laravel.

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

    Thanks

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

    by this video you can understand the principle of has_many and belongs_to in other languages and frameworks also

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

    Thanks or putting this together. If you had a page that needs to display say for every employee, the country, city and shop, what might the query look like?

  • @AbdulMajeedShehzad
    @AbdulMajeedShehzad 2 ปีที่แล้ว +7

    Thank you for the great video, I've a question for this scenario. is it a good practice to use keys in deep relations ? for example in employees table we add country_id to avoid complex queries when working on reporting. I've been looking for this answer for quite a long time

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

      Up

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

      Feel you bro, done the same: usign foreign keys to those deep deep relationships

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

    what package did you used to showing relation and through text in the model?

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

    Thanks for this how can i learn more about eager loading

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

    What if we want to update data? I have a Sales Order, with Items, and each item has a list of Operation IDs to produce the item

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

    great video thanks. :)
    but i think in some situation like this performance will drop after 2 joins and more.
    I mostly using DB facade for retrieving data from database.

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

      Yes, for complex queries raw queries are still the best.

  • @insider-analyst
    @insider-analyst 2 ปีที่แล้ว

    composer require staudenmeir/belongs-to-through:"^2.5"
    not installing on laravel 8

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

    really helped me with retrieving data, but what about insert data? is it possible to do so?

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

    What about A -> many to many -> B belongs to -> X, is possible using this package to access X from model A ?

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

    Could you make one video of belongstomany with three level deep query with where condition (with the last one)?

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

    royal like from me!

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

    Thanks for your videos! Could you please do one about constructing relationships between tables that are in different databases and connection names to those tables cannot be hard coded. E.g.: User table is in DB1, Post table is in DB2 and Comment table is in DB3. Can we construct a relationship here? Thanks!

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

      It will work the same, the only thing you will have to do is overwrite the connection variable inside of the model.

  • @Ayvengo21
    @Ayvengo21 2 หลายเดือนก่อน +1

    All the time i see that orm magic like this I'm asking myself does it worth it or maybe some escaped sql would be way easier to read and write. Because sql knowledge could be transferred between projects while knowledge of specific orm might be problematic.

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

    You do not show how to set search filter with "with" relation and its deep level with multiple column. Can you do that?

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

    Sir, @LaravelDaily If i want to add another table: shop_branches fields: 1) id 2)shop_id 3) shop_branch_name
    then how i define relationship to access: shop_branch_name

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

    how can we select only some attributes of the second table?

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

    @ 8:00 you are showing off the functionality of `hasManyDeep` to associate employees with their countries. Could this also be achieved with an additional `hasManyThrough` definition? Where it is defined as `hasManyThrough(Employee::class, Shop::class)` ? Or do those methods not chain well / is this strictly better for performance?

  • @yogeshwarbarai9686
    @yogeshwarbarai9686 10 หลายเดือนก่อน

    what ide setup you use ? It looks so good and to the point

    • @LaravelDaily
      @LaravelDaily  10 หลายเดือนก่อน +1

      Phpstorm default

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

    how to query with scope to show id 1 from shop ?

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

    Great content, can you make a video on user referral system using laravel Eloquent

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

    how to get all data of that relationships not through some. ex all countries, and all cities and all shop in 1 query, i wanna make tree.. pls advice sir

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

    Hi, I watched your video about function's return type, is there any documentation about the full list of return types? Thank you!

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

      Any PHP variable type or PHP/Laravel class could be a return type. There's no list.

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

    how to get limited relationship data with using laravel and mongo db please give me solution thank you