How do you check "if not null" with Eloquent? How do you check "if not null" with Eloquent? laravel laravel

How do you check "if not null" with Eloquent?


Eloquent has a method for that (Laravel 4.*/5.*);

Model::whereNotNull('sent_at')

Laravel 3:

Model::where_not_null('sent_at')


If someone like me want to do it with query builder in Laravel 5.2.23 it can be done like ->

 $searchResultQuery = Users::query();  $searchResultQuery->where('status_message', '<>', '', 'and'); // is not null $searchResultQuery->where('is_deleted', 'IS NULL', null, 'and'); // is null 

Or with scope in model :

public function scopeNotNullOnly($query){    return $query->where('status_message', '<>', '');}


If you wanted to use the DB facade:

DB::table('table_name')->whereNotNull('sent_at')->get();