Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:11:23+00:00 2026-06-17T04:11:23+00:00

I have two tables, Galleries and Gallery_items . In Galleries I save information like

  • 0

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)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:11:24+00:00Added an answer on June 17, 2026 at 4:11 am

    Thanks to @AndHeiberg i started to see the problem from other perspectives and I have now solved the problem using a JOIN statement.

    Gallery_items::join('gallery', 'Gallery_items.gallery_id', '=', 'gallery.id'))->group_by('gallery_id')->where_title_and_author('Mona Lisa', 'Leonardo da Vinci');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these two tables: Galleries - {id,title,description} Images - {id,gallery_id,file} Each gallery has
I have two tables, one that roughly looks like: client_ip server_ip speed --------- ---------
I have two tables. One contains Potential Customer information along with their Vehicle requirements
Should a database table that contains two columns that are foreign keys have a
I have two tables that I can perfectly query seperately. table1 stores ranges: SELECT
I have a MYSQL database of photo galleries; each row contains a field with
I have two tables: gallery and pictures: gallery id int (auto increment, primary key)
I have two tables: Holdings and Transactions Holdings data looks like: 06/30/2009, A, 100
I have two tables I would like to join with GroceryCRUD . Part of
I have two tables, like this: master --------- empcode INT PRIMARY KEY name VARCHAR

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.