Chandimal Harischandra
Chandimal Harischandra

Reputation: 315

Laravel whereDate and where

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?

Upvotes: 6

Views: 53320

Answers (2)

Chata
Chata

Reputation: 85

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'))

Upvotes: 2

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You should try this:

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

Upvotes: 24

Related Questions