mercredi 30 août 2017

Different relationships on different model types Laravel

I wonder how you'd go about my problem where I am going to display different types of events. For example 2 different events could be a soccer event and a formula1 event.

In these 2 scenarios there are different types of participants. In a soccer game this would be the 2 teams, and in a formular1 event it would be all the drivers.

Here are my Eloquent example of what I would like to do:

public function participants()
{
    if ($this->type == 'soccer_game') {
        return $this->hasMany(EventTeam::class);
    } else if ($this->type == 'formula1_race') {
        return $this->hasMany(EventDriver::class);
    }
    return $this;
}

But when trying this and try to load it I get the error "Call to undefined method Illuminate\Database\Query\Builder::addEagerConstraints()".

I think I need a push in the right direction.

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iGY2qQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire