Skip to main content

HasManyThrough: 2-Level Deep hasMany

Premium
1:45

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 33 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

PS
Prince Sonawane ✓ Link copied!

we have multiple task for the user in the above given condition and I want to filter it out by created at date or specific task for all users which might be assigned on different dates. how to achive that? for the same I am trying with product > product_variants > daily_stocks. I want to filter daily_stock on conditions like issued_stock = 100. so expected output are only product with product record and daily_stock records where on the days when 100 records where issued.

PK
Povilas Korop ✓ Link copied!

Well, you could use hasManyThrough and then do Product::whereHas('daily_stocks', function($query) { $query->where('issued_stock', 100); } maybe?

S
Scarecrow0w ✓ Link copied!

What would you recommend for the inverse of this relation - "belongs to through"? As I know, Laraver doesn't provide method BelongsToThrough

PK
Povilas Korop ✓ Link copied!

There's a package for this: staudenmeir/belongs-to-through

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.