如何写远程一对多反向?
文档中只说明 远程一对多 使用
countries
id - integer
name - string
users
id - integer
country_id - integer
name - string
posts
id - integer
user_id - integer
title - string
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
{
/**
* 当前国家所有文章
*/
public function posts()
{
return $this->hasManyThrough('App\Models\Post', 'App\Models\User');
}
}
这是文档
https://learnku.com/docs/laravel/8.x/eloquent-relationships/9407#has-many-through
那么反向改如何写? 想知道 这篇文章属于那个国家的?
反向就是hasOneThrough关联,调整好几个参数对应的字段,就能关联出来了