No you cant go deeper.
then what you can do depends on what you want to achieve. Arn't nested foreach sufficients ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have an eloquent relationship that I am trying to achieve.
So far I have :
Country
Users (country_id)
Posts (user_id)
Comments (post_id)
Now if I want to get all users from a country I do:
public function users()
{
return $this->hasMany('App\Http\Models\User');
}
If I want to get all posts from a country I do:
public function posts()
{
return $this->hasManyThrough('App\Http\Models\Posts', 'App\Http\Models\User');
}
How can I go about getting all comments from a country as the link is country->users->posts->comments?
Is there a way to go deeper such as nested hasManyThrough?
Why not use nested foreach in you view ?
@foreach($country->users as $user)
@foreach($user->posts as $post)
Etc ...
@endforeach
@endforeach
Please or to participate in this conversation.