E
E
Emil Rakhmatullin2019-10-22 15:11:49
Laravel
Emil Rakhmatullin, 2019-10-22 15:11:49

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 eventsusers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kokhan, 2019-10-22
@SkazochNick

Look here - https://www.youtube.com/watch?v=GPk3soWIP0E

E
Eduard Bazhenov, 2019-10-22
@kip_34

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 question

Ask a Question

731 491 924 answers to any question