Laravel Eloquent whereNotNull
When querying your Laravel Eloquent you can directly chain the "whereNotNull()" from the model itself.
<?php $posts = Post::query() ->whereNotNull('published_at') ->get();
Laravel Query Builder whereNotNull
If you do prefer using the "DB" facade then you can write your code with the "whereNotNull()" condition like below.
<?php $posts = DB::table('posts') ->whereNotNull('published_at') ->get();
Inverse of whereNotNull
The inverse of "whereNotNull()" is "whereNull()" and this method will check if the value is NULL.
<?php Post::query() ->whereNull('published_at') ->get(); DB::table('posts') ->whereNotNull('published_at') ->get();
Leave a reply