Shafee Shafee - 2 years ago 166
PHP Question

Laravel 5.2 : Elequent deleted_at Null/!Null with where clause and count

I am using eloquent to fetch some records on the basis of condition.

$completed = Task::where('user_id', Auth::user()->id)->where('deleted_at', '=', !Null)->get()->count();

$incompleted = Task::where('user_id', Auth::user()->id)->where('deleted_at', '=', Null)->get()->count();

The first one returns
which is correct.
But the second one returns
which should be

Table :

Table Data

Am i missing something ?

Answer Source

Your queries should look like this:

$completed = Task::where('user_id', Auth::user()->id)->onlyTrashed()->get()->count();

$incompleted = Task::where('user_id', Auth::user()->id)->get()->count();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download