如何找到与 Eloquent ORM 的关系的关系?目前我有这样的东西。简单的关系。我可以找到图片,它是摄影师。现在我需要做一些更复杂的事情,我还需要找到摄影师标签。
转储看起来像这样
object(Image) {
["attributes"] => [],
["relationships"] =>
["photographer"] =>
["attributes"] => [],
["relationships"] =>
}
但我需要添加标签关系,所以它看起来像这样
object(Image) {
["attributes"] => [],
["relationships"] =>
["photographer"] =>
["attributes"] => [],
["relationships"] =>
["tags"] =>
["attributes"] => [],
["relationships"] =>
}
这怎么可能?
/图像模型
public function photographer()
{
return $this->belongs_to('Photographer');
}
public function tags()
{
return $this->has_many_and_belongs_to('Tag', 'tag_relationships');
}
/控制器
$images = Image::with(['photographer'])->order_by('updated_at', 'desc')->get();