I have two tables, Galleries and Gallery_items.
In Galleries I save information like who the author is. In Gallery_items I save each picture that the gallery contains.
Now I want to get the first picture in each gallery where the title is mona lisa and where the author is Leonardo da Vinci.
I tested:
Gallery_items::group_by('gallery_id')->where('title', '=', 'mona lisa')->gallery()->where('author', '=', 'Leonardo da Vinci');
But it doesn’t work. I get an error Method is not defined on the Query class..
But I have added gallery() to the model.
class Gallery_items extends Eloquent
{
public function gallery()
{
return $this->belongs_to('gallery');
}
}
Any idea how I should do?
Is this even possible with one query?
Is “Constraining Eager Loading” maybe the answer (I don’t get what that is)?
Thanks to @AndHeiberg i started to see the problem from other perspectives and I have now solved the problem using a
JOINstatement.