I have 3 tables:
users
- id
- name
place
- id
- name
place_waiter_pivot
- user_id
- place_id
One place can have many users (waiters), but a user can be assigned only to one place (also user doesn't have to be a waiter, so he will not belong to any place in this case).
So far I have this relations written, but they don't work. What am I doing wrong here?
Place model:
public function waiters(): HasManyThrough
{
return $this->hasManyThrough(User::class, 'place_waiter_pivot');
}
User model:
public function waiter(): HasOneThrough
{
return $this->hasOneThrough(Place::class, 'place_waiter_pivot');
}
Well, your usage may not be appropiate for the scenario you want. So, using belongsToMany should resolve your problem.
You can try to change your code like this:
And in your user model: