Tuesday, February 28, 2017

Get all championships that are teams in Eloquent

I have a tournament, a tournament can have many >

public function championships()
{
    return $this->hasMany(Championship::class);
}

and a Championship hasOne Category. In Category, I have the isTeam attribute.

Now I need a function that get me all the championships that have the isTeam = 1 in Category table.

public function teamChampionships()
{

}

Of course, I have defined : $tournament->championships, $championship->category

In my controller, I get all of them:

        $tournament = Tournament::with('championship.category')->find($tournament->id);

Any idea???




via Juliatzin del Toro

Advertisement