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

thijn's avatar
Level 2

Receiving a pivot relation through another pivot relation

Hello,

I was wondering if it is possible to make a relation function to directly retrieve models with two pivots in between. We created the following models/pivots:

Group
functions: users, websites

GroupUser (pivot)
columns: group_id, user_id
functions: group, user

GroupWebsite (pivot)
columns: group_id, website_id
functions: group, website

Website
functions: groups, users(?)

User
functions: groups, websites(?)

Is it possible to get a websites relation directly from the user class or is it only possible to retreive all groups and then the websites from the groups with multiple queries?

0 likes
0 replies

Please or to participate in this conversation.