Laravel whereDate() is not working as expected

  eloquent, laravel

The following is part of my query for querying data between two dates:

->whereDate('fixture_date', '>=', Carbon::now()->subDays($pastDays))
->whereDate('fixture_date', '<=', Carbon::now()->addDays($futureDays))
->when(request('search'), function ($query) {
    $query->orWhere('fixture_hometeam_name', 'LIKE', '%' . request('search') . '%')
          ->orWhere('fixture_awayteam_name', 'LIKE', '%' . request('search') . '%');
        })

When request('search') is empty, I am getting the expected results but when not, the whereDate queries are not working.

How should this be modified to give the correct results?

Source: Laravel

Leave a Reply