Recently I set up GitHub sponsors, if my content helps you, you can consider a one-time or monthly sponsorship.

Laravel's HasManyThrough cheatsheet

This is where the ad would go. Instead though, I'd like to point you towards my GitHub Sponsors page. If you're a regular reader and my content is helping you, you can consider a one-time or monthly sponsorship. If you're a company looking for dedicated ad placements on this blog or my newsletter, you can email me at brendt@stitcher.io

- The current model Country has a relation to Post via User
- The intermediate model is linked to the current model via users.country_id
- The target model is linked to the intermediate model via posts.user_id
- users.country_id maps to countries.id
- posts.user_id maps to users.id
countries
    id - integer
    name - string

users
    id - integer
    country_id - integer
    name - string

posts
    id - integer
    user_id - integer
    title - string
class Country extends Model
{
    public function posts()
    {
        return $this->hasManyThrough(
            'App\Post',
            'App\User',
            'country_id', // Foreign key on users table...
            'user_id', // Foreign key on posts table...
            'id', // Local key on countries table...
            'id' // Local key on users table...
        );
    }
}