Laravel hasManyMerged relation with condition

  eloquent, laravel

I have a self-related Laravel model Fixture.

To get home team fixtures, I am using KorridorLaravelHasManyMerged as follows:

public function homeTeamFixtures()
{
    return $this->hasManyMerged(Fixture::class, ['fixture_hometeam_id', 'fixture_awayteam_id'], 'fixture_hometeam_id');

}

This works perfectly fine and returns all home team fixtures.

However, I only want fixtures that happened before the current one. I have tried the following but does not return any results.

    public function homeTeamFixtures()
    {
        return $this->hasManyMerged(Fixture::class, ['fixture_hometeam_id', 'fixture_awayteam_id'], 'fixture_hometeam_id')
            ->whereRaw('fixture.fixture_date > fixture.fixture_date');

    }

How do I get the relevant results?

Source: Laravel

Leave a Reply