Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DilipkumarC's avatar

Laravel check the date

Hi,

Is there the proper way to check the database date if smaller than "before date" then do the restriction?

currently What I have is

        if (count(Sale::where('date','<=' ,'2018-08-01')->get()) > 0 ) {
            echo "Sales is closed";
            return false;
        }else {
            echo "Sales is open";
            return true;
        }

The sale will closed for the date that before 2018-08-01 and new sale will open after the date.

0 likes
3 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@dilipkumarc

You can use count() method directly after the query.

For example-

if (Sale::where('date','<=' ,'2018-08-01')->count() > 0 ) {
    //restriction
}else {
   //not restrication 
}
6 likes

Please or to participate in this conversation.