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

gborcherds's avatar

Help with pivot relationships

Hi there,

Pretty new to Laravel, but making progress. I'm having trouble with a specific use case I'm working on. I have two tables, users and letters. A letter can obviously have multiple users, but where my situation is different is that the type of user can be different and I used three separate relationship tables in my previous app. So a user can be the creator, an editor, or just a reader of a particular letter. That same user could have a different "role" on a different letter. The way I set this up before was as follows:

users
 --user_id

letters
 --letter_id

creator_user
 --user_id
 --letter_id

admin_user
  --user_id
 --letter_id

reader_user
  --user_id
  --letter_id

I'm not sure what the right structure would be for laravel. I was looking into polymorphic relationships and something like that might work. I'm willing to change the structure completely if there is a better way to design it. I'm just hoping to be able to pull a user and then pull all the letters that they are an admin of and then at the same time pull all the letters that a user has creator access to.

I've also looked at doing this with a simple table structure like this:

users
 --user_id

letters
 --letter_id

letter_user
  --user_id
  --user_id
  --user_type (which can be the three types)

But I don't understand how the pivot relationships work with this setup.

Any thoughts?

0 likes
0 replies

Please or to participate in this conversation.