Rajveer Singh
Rajveer Singh

Reputation: 433

error when calling data from created_at using where

hey so im trying to display a graph based on selected from and to from user. the column that it will call is from created_at column but when i write my code like

$email = count(DiraResponses::where('company_id', $companyID)->where('created_at', '>=', $request->from)->where('created_at', '<=', $request->to)->where('type', 'email')->where('format', 'email')->get());

it returns an error FatalThrowableError in FileSessionHandler.php line 70: Call to undefined method Carbon\Carbon::getTimestamp()

how should i solve this? this error comes only when i call the created_at column.

Upvotes: 1

Views: 78

Answers (2)

NIKHIL NEDIYODATH
NIKHIL NEDIYODATH

Reputation: 2932

You can use the following syntax to get count.

$email = DiraResponses::
    where([['company_id', $companyID],
    ['created_at', '>=', $request->from],
    ['created_at', '<=', $request->to],
    ['type', 'email'],
    ['format', 'email']])
    ->count();

Upvotes: 1

Kaleem
Kaleem

Reputation: 201

Try using whereDate() function while comparing dates like this.

whereDate('created_at', '>=', $request->from)->whereDate('created_at', '<=', $request->to)

Also don't forgot to format your comparison date same as your database formate for example

$from = date('Y-m-d' , strtotime($request->from));

And then pass $from in the query

Upvotes: 1

Related Questions