Laravel whereDate and where

Viewed 27200

I'm using laravel 5.4, and I need to check both event and created date conditions at once. So I used following code,

  protected $table = 'qlog';   
        public $timestamps = false;

        public function getAbondonedCalls(){

        $results =  DB::table('qlog')
            ->whereDate('created', '=', DB::raw('curdate()'))
            ->where('event', '=', 'ABANDON')
            ->get();  

             var_dump($results);
            die(); 

}   

But this code returns nothing. After removing this line it returns a record.

 ->whereDate('created', '=', DB::raw('curdate()'))

How to add both conditions?

2 Answers

You should try this:

->whereDate('created', '=', date('Y-m-d'))

For convenience, if you want to verify that a column is equal to a given value, you may pass the value directly as the second argument to the whereDate method: i.e. without including '=' sign

->whereDate('created', date('Y-m-d'))
Related