Home > Enterprise >  Laravel get data which has date set and which has date empty
Laravel get data which has date set and which has date empty

Time:06-10

I have the following table:

enter image description here

In this table the column start_at and end_at columns are nullable.

And I want to fetch the rows which has end_at filled and end_at not filled. And end_at should be greater than equal to todays date.

I.E: Don't fetch rows which has end_at date older than today.

My code sofar:

    $date = today()->format('Y-m-d');
    $informations  = Information::where('end_at', '>=', $date)->get();

What query should I use to check the condition on same column ?

CodePudding user response:

This should do the trick

Information::where('end_at', '>=', $date)->orWhereNull('end_at')->get();
  • Related