WhereNotNull method in Laravel
If you want to check whether a field is NOT NULL, it is possible to check that in Eloquent. Suppose you want to select all the results where sent_at column values are not null. In Laravel 4 and 5 we can write it as given below
DB::table('table_name')->whereNotNull('sent_at')->get();
or
Model::whereNotNull('sent_at')
whereNotNull is a method of Laravel.
There is another method called WhereNull. It can be used to check the null fields. For example, if you want to check the null in the deleted_at field you can use WhereNull
Model::whereNull('deleted_at')
Comments
0 comments
Please Sign in or Create an account to Post Comments