Unfortunately, there is no easy solution, so I realized that I found
1- hasMany ,
posts
id - integer
country_id - foreign
// etc...
title - string
2- hasManyThrough , user post, , ,
countries
id - integer
name - string
cities
id - integer
country_id - foreign
name - string
towns
id - integer
city_id - foreign
name - string
users
id - integer
town_id - foreign
name - string
posts
id - integer
user_id - foreign
title - string
-
1- hasMany
2- hasManyThrough .
3- Country::whereName('xx')->posts
public function posts()
{
$posts = [];
foreach ($this->towns as $town) {
$posts[] = $town->posts;
}
return $posts;
}
4, foreign_id, id name, Country::find($id)->posts()