I see this question is a bit old but I ran across it looking for an answer. Although I did not have success with the answers here I think this might be because I'm on PHP 7.2 and Laravel 5.7. or possible because I was just playing around with some data on the CLI using Laravel Tinker.
I have some things I tried that worked for me and others that did not that I hope will help others out.
I did not have success running:
MyModel::whereNotNull('deleted_by')->get()->all(); // []
MyModel::where('deleted_by', '<>', null)->get()->all(); // []
MyModel::where('deleted_by', '!=', null)->get()->all(); // []
MyModel::where('deleted_by', '<>', '', 'and')->get()->all(); // []
MyModel::where('deleted_by', '<>', null, 'and')->get()->all(); // []
MyModel::where('deleted_by', 'IS NOT', null)->get()->all(); // []
All of the above returned an empty array for me
I did however have success running:
DB::table('my_models')->whereNotNull('deleted_by')->get()->all(); // [ ... ]
This returned all the results in an array as I expected. Note: you can drop the all()
and get back a Illuminate\Database\Eloquent\Collection instead of an array if you prefer.