ThinkPHP 5 how to check data by cross-table one-to-many Has Many Through

you could have checked User, through Conuntry and then Post, through User. Now you can check Post; directly through Country
usually the relationships between Country and User,User and Post are established beforehand, and then you can use hasManyThrough;

at this time.

Table structure:
country
id-integer
name-string

user
id-integer
country_id-integer
name-string

post
id-integer
user_id-integer
title-string

namespace App;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
{
    public function posts()
    {
        return $this->hasManyThrough("Post", "User", "country_id", "user_id");
        
    }
}

call:

$country = Country::get(2);
$posts = $country->posts();

this allows you to get id=2, all of the country"s articles. But which high-ranking person knows how to tie back through an article which country id=100 belongs to?

Mar.03,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e43491-449fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e43491-449fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?