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

gustav1105's avatar

How to define these relationships in my models.

U have three models

Advertiser
Reference
AdvertiserReference

How would I setup the relationships between these models, for the tables

advertisers 
references
advertiser_references //this is a pivot table

It goes a something like this.

There are 5 advertisers in the advertisers table and there are

1000 references in the references table.

In the advertiser_references tabel it should be thus that

each reference is connected to an advertiser, and a reference can only have one advertiser.

something like this

advertiser one -> 1234
advertiser two ->1235
advertiser three ->1236
advertiser two -> 1237
advertiser one -> 1289

Looking at elqouent with the three models how would I define these relationships on my three models.

Thanks.

0 likes
2 replies
marthz's avatar
marthz
Best Answer
Level 17

If each reference only has one advertiser you don't need a pivot table, an advertiser_id in the references table is enough.

Then in the eloquent side you have to set up a hasMany/belongsTo relationship.

Please or to participate in this conversation.