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

xuuto's avatar
Level 2

is it appropriate to use custom pivot models for this many to many in staff role?

there is three tables in my relationships. and the tables are

staff table

id
first_name
last_name


role Table

id
role_name
is_staff_role bool
is_partner_role bool


sraff_role table

id
gallery_id FK
staff_id  FK
role_id Fk
role_start_date date
role_end_date date Nullable

as you can see staff_role table is pivot table, so how can i insert gallery_id foreign key which has one to many relationship with galleries table.

and also role_start_date and role_end_date

i heard about that pivot tables can be made with models. so is that the appropriate way for this pivot table?

0 likes
1 reply
SilenceBringer's avatar

Hi @xuuto of course if it better feets your needs, you can think about staff_role table as a separated table (not simple intermediate table), and create separated model for it. Just don't forget to change relation type in this case from belongsToMany (used with pivot table) to hasMany to StaffRole model

Please or to participate in this conversation.