Looks like you might need to use hasManyThrough?
https://laravel.com/docs/5.4/eloquent-relat...as-many-through
[Help] Laravel eloquent, working with tables
[Help] Laravel eloquent, working with tables
|
Jun 19 2017, 07:05 PM
Return to original view | Post
#1
|
Senior Member
1,914 posts Joined: Aug 2009 |
Looks like you might need to use hasManyThrough?
https://laravel.com/docs/5.4/eloquent-relat...as-many-through |
|
Jun 20 2017, 04:57 PM
Return to original view | Post
#2
|
Senior Member
1,914 posts Joined: Aug 2009 |
Model in Table A:
CODE public function tablec() { return $this->hasManyThrough('App\TableC', 'App\TableB', 'tableB_id', 'id'); } Controller: CODE $enteries = TableA::get(); foreach($enteries as $ent) { var_dump($ent->tablec); } Not entirely sure this code is correct or not, you'll have to play around with it.. your table structure is very similar to the one on Laravel docs so it shouldn't be too tough to get the results. The way you're doing now is fine for relatively small tables but if your tables gets larger, it might just be better to figure it out using Eloquent because you can lazy load the stuff which means less heavy queries. This post has been edited by JusticeDeserves: Jun 20 2017, 04:57 PM |
Change to: | 0.0126sec
0.28
6 queries
GZIP Disabled
Time is now: 29th March 2024 - 08:16 PM |