我有两个表,Galleries
和Gallery_items
。 在Galleries
我保存作者是谁的信息。在Gallery_items
我保存该图库包含的每张图片。Laravel中的关系
现在我想获取的第一张图片中每个画廊其中标题是蒙娜丽莎并在作者是达芬奇。
我测试:
Gallery_items::group_by('gallery_id')->where('title', '=', 'mona lisa')->gallery()->where('author', '=', 'Leonardo da Vinci');
但它不工作。我收到错误Method [gallery] is not defined on the Query class.
。
但我已经添加gallery()到模型。
class Gallery_items extends Eloquent
{
public function gallery()
{
return $this->belongs_to('gallery');
}
}
任何想法我应该怎么做? 这甚至有可能与一个查询? “Constraining Eager Loading”也许是答案(我不明白那是什么)?
否,因为'Gallery_items'没有名为'author'的列。这是'画廊'有那一栏。 – Sawny