Laravel Eloquent: Deeper Relationships with One Query

Поделиться
HTML-код
  • Опубликовано: 29 июн 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 3 года назад +66

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

  • @0x0456
    @0x0456 Год назад +2

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

  • @pankajbokdia
    @pankajbokdia 2 года назад +11

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

  • @tiagooliveira14
    @tiagooliveira14 3 года назад +31

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

    • @LaravelDaily
      @LaravelDaily  3 года назад +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.

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

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

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

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

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

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

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

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

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

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

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

  • @salman-804
    @salman-804 2 года назад +2

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

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

    Your videos are always wonderful.

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

    Thanks for your laravel daily tips.

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

    OMG, this is amazing thank you so much!

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

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

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

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

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

    This is really great. Love it

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

    Your tutorials help a lot... Thanks

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

  • @user-zg1pc6md6y
    @user-zg1pc6md6y 3 года назад +10

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

    • @user-ld1gz1cr1j
      @user-ld1gz1cr1j 3 года назад

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

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

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

  • @msdeav
    @msdeav 3 года назад +2

    Really helpful video. Thank you

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

    Problem solving, thanks sir!

  • @shahosanandaji9894
    @shahosanandaji9894 10 месяцев назад

    You are the best, Povilas!

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

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

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

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

  • @vigneswarans13
    @vigneswarans13 4 месяца назад

    Excellent explanation 🎉

  • @md.robelahammed4763
    @md.robelahammed4763 Год назад

    Amazing content. It helps me a lot. Thanks

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

    Wow! that`s really really awesome!

  • @vbadheli
    @vbadheli 3 года назад +2

    Thank you.. this help me a lot..

  • @demeja16
    @demeja16 3 года назад +9

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

    • @maxgoose4671
      @maxgoose4671 3 года назад +2

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

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

    Very informative video, thanks.

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

    you always provide good content

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

    very very very helpful package thanks !

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

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

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

    Really good job. Thanks 🙏

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

    Thank sir , one of the best video

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

    Great video💙

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

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

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

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

  • @user-rm4zo1mg5o
    @user-rm4zo1mg5o 3 года назад

    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

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

    🎉 save the day, thanks a lot

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

    thank you very much for tutorial sir!!

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

    awesome, thanks you, please more and more advanced eloquent

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

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

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

    Thx for the great content

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

    Brilliant!

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

    You are awesome 😍

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

    Good job!

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

    Helpful 🙌🖤

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

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

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

    Awesome!

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

    Pretty helpful!

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

    This is cool!!!

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

    good work!!!

  • @AlexTheGreatish
    @AlexTheGreatish 3 года назад +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  3 года назад +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

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

    Lovely!

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

    great, thank you!

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

    Best video. 👌

  • @YT-Gmailer
    @YT-Gmailer 3 года назад

    Thank you!

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

    very well. thank you.

  • @claudiomenares4172
    @claudiomenares4172 4 месяца назад

    Muchas gracias 🤯

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

    The best....Thanks

  • @RANJEETKUMAR-wz4dg
    @RANJEETKUMAR-wz4dg 3 года назад

    amazing thanks

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

    awesome!!

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

    very helpfull
    thanks

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

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

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

    thank you very much

  • @newtonsefa5721
    @newtonsefa5721 10 месяцев назад

    Thank you

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

    Thanks 👏

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

    Thanks 🙏

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

    Amazing

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

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

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

    thank you

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

    thanks a lot

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

    royal like from me!

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

    Thanks

  • @arashpirhadi1326
    @arashpirhadi1326 3 года назад +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  3 года назад +2

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

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

    thanks

  • @afestacincome2224
    @afestacincome2224 3 года назад +4

    Can you please do a Short video on how to create nested comment and also a Short video on how to retweet a post ( Just like Twitter)

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

      Retweet feature will be nice

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

      @@ikarahubs965 nested comment please

  • @AbdulMajeedShehzad
    @AbdulMajeedShehzad 3 года назад +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

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

    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?

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

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

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

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

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

    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.

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

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

    The BelongsToThrough query actually became less efficient, no? It reduced the queries and models used but memory and time to execute increased.

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

      exactly, it slowed it down but it did simplify the work, so if you're application doesn't require or need the small performance difference, it's a good choice though.

  • @Ayvengo21
    @Ayvengo21 3 месяца назад +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.

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

    Thanks for this how can i learn more about eager loading

  • @dApoTB
    @dApoTB 3 года назад +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 3 года назад

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

  • @insider-analyst
    @insider-analyst 2 года назад

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

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

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

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

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

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

    I follow all of your video u are great because the laravel path am on is just what u can teach so I need ur personal contact.

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

  • @yogeshwarbarai9686
    @yogeshwarbarai9686 11 месяцев назад

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

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

    6:03 the query count went down but the time & memory usage went up, less performant 🤔maybe it is not using an index

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

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

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

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

    Very helpful video.
    Why laravel framework does not have these kind of relationships yet?

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

      You're free to submit pull requests to the framework and add it.

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

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