Laravel Eloquent whereNull() and whereNotNull() Query
In this tutorial, we will learn Laravel Eloquent whereNull() and whereNotNull() Query Example. We will explain Laravel Eloquent whereNull() Query Example to check is a null value in a database table. We use Laravel Eloquent use whereNull() Query functionality. Laravel default provides Eloquent whereNull() method. In this post, we will simple example of Laravel where null example and eloquent whereNotBetween() query to get dates-wise data from a database table. We will look at an example of wherenull() Laravel’s eloquent example.
Also read: Laravel Eloquent whereNotBetween() Example
We will give a very simple example of how to use whereNull() and whereNotNull() in Laravel. whereNull() will help you to get data with null values from the database users table. and whereNotNull() will help you to get data with not null values from the database users table.
I would like to share Laravel Eloquent whereNull() and whereNotNull() Query Example Example. In this tutorial you will learn how to check IS NULL value.
whereNull()
Also read: How to Display Laravel DB Query
SQL Query:
select * from `users` where `email_verified_at` is null
Laravel Query:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller {
public function index() {
$users = User::select("*")->whereNull('email_verified_at')->get();
dd($users);
}
}
Also read: Laravel eloquent where the like query
whereNotNull()
SQL Query:
select * from `users` where `email_verified_at` is not null
Laravel Query:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller {
public function index() {
$users = User::select("*")->whereNotNull('email_verified_at')->get();
dd($users);
}
}