mercredi 24 février 2016

Laravel 5.2 hasManyThrough relationship issue

I have 3 tables: orders, codes, events

I want to be able to pull all events that an order has, but there's an intermediary table that acts as a pivot table. I've been trying to use hasManyThrough and belongsToMany (along with withPivot) without any luck.

Examples:

public function events()
{
    return $this->belongsToMany('events'); // tried this, fails
    return $this->hasManyThrough('events', 'codes'); // tried this, fails
    return $this->hasManyThrough('events', 'codes', 'event_id', 'id'); // tried this, fails
}

Any pointers would be great!

example image



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire