Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kelrob's avatar

Help in Fetching of records

Hello Laracasts!!

So I am having an issues with fetching a particular kind of record from the database.

I have three different tables

  1. Friends
  2. Followers
  3. PictureGalleries

Here are the table structures

Friends:

| id | senderId | receiverId | accepted | |----|----------|------------|----------| | 1 | 1 | 12 | 1 | | 2 | 12 | 2 | 1 | | 2 | 12 | 2 | 1 |

Followers:

| id | userId | UserIsFollowing | | ------------- | ------------- | ------------- | | 1 | 12 | 63 | | 2 | 22 | 12 |

PictureGalleries:

| id | UserId | | ------------- | ------------- | | 1 | 13 | | 2 | 12 | | 3 | 1 | | 4 | 10 | | 5 | 2 | | 6 | 63 |

So now here is the Issue!

I want to select all from the Picture Galleries Where the the user has a friendship relationship with a particular user Id where accepted is 1 And Where the user is following a particular user

Lets take this User has an Id of 12.

So Basically the result I want to see is the picture gallery of the following users

ID: 1,2, and 63

I just Hope I did not confuse You guys. Thanks!

0 likes
1 reply
Mo7sin's avatar

Show us your relationships between these Models, please!

Please or to participate in this conversation.