我写这篇文章是因为我在 Laravel 上的关系有问题。
这是我目前拥有的结构:
第一个表: - id - 名称 - ...
第二张表: - parent_id - child_id
知道 parent_id 和 child_id 对应同一张表。这是链接它们的函数
public function relation()
{
return $this->belongsToMany('App\Person', 'person_relations', 'parent_id', 'child_id', 'id', 'id');
}
目前,对于搜索系统,我想在表 1 中获取所有人,而不是在表 2 中获取以我为 parent_id 的人。