Answer the question
In order to leave comments, you need to log in
How to get the user's events to which he subscribed?
It's hard for me to understand how to build a relationship...
There are tables:
users
id
events
id
joins
id
user_id
event_id
How can I get all events
users?
Answer the question
In order to leave comments, you need to log in
class User extends Model
{
/**
* The events that belong to the user.
*/
public function events()
{
return $this->belongsToMany('App\Event');
}
}
$user = App\User::find(1);
foreach ($user->events as $event) {
//
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question