I'm not able to use whereNotNull in my query. I need to check if the column "fresh_until" is not null. If it is not null, we check the date as well.
->when($this->date, function ($query){
$query->whereHas('food.date', function ($query){
$query->where('valid_from', '<=', $this->date); //this works perfectly
$query->whereNotNull('fresh_until') //this not
->where('fresh_until', '>=', $this->date);
});
})