lundi 5 juin 2017

Laravel Eloquent belongsToMany mutiple foreign keys

In laravel I'm connecting events to users like this:

class User extends Model 
{
    public function events()
    {
        return $this->belongsToMany('App\Event', EventUser::TABLE_NAME, 'user_id', 'event_id');
    }
}

which works great, but now I'm implementing repeat feature so I'm inserting repeating events for 2 years in the future in the database, and I don't want to make 1000 inserts, so I decided that I'll have parent event, and subevents will have parent_id in the database. Now the problem is that I can't get those events with belongsToMany, since I need to watch for 2 foreign keys... id and parent_id.

Any idea how I can do that? I want to get events connected with user and events that have parent event connected with user.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire