Reputation: 3757
I'm having trouble setting up a relationship within my application using Laravel/Eloquents relationship syntax.
I have:
Events
- id, name, location
Reservations
- id, event_id, user_id
Users
- id, name, etc
and I want to be able to grab "All users objects across all reservations for a given Event". I have tried using hasManyThrough
with the various argument sets to get this result set, but am coming up with empty sets!
Any insight is appreciated.
Upvotes: 0
Views: 59
Reputation: 7992
The users
table should have reservation_id
foreign key of reservations table if you are looking for hasManyThrough
relationship.
If you need to obtain
All users objects across all reservations for a given Event
You could use
$users_with_reservation = Reservation::where('event_id', $event_id)->pluck('user_id');
$users = User::whereIn('id', $users_with_reservation)->get();
Upvotes: 1