ItSolutionStuff.com

Laravel Eloquent whereNull() Query Example

By Hardik Savani • April 16, 2024
Laravel

I will explain step by step tutorial laravel wherenull example. This post will give you simple example of laravel where null example. We will look at example of wherenull laravel eloquent example. This post will give you simple example of laravel wherenull wherenotnull.

In this example i will give you very simple example of how to use whereNull() and whereNotNull() in laravel application. you can easily use it with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 application.

whereNull() will help you to getting data with null values from database.

whereNotNull() will help you to getting data with not null values from database.

So, let's see bellow examples that will help you how to use whereNull() and whereNotNull() eloquent query in laravel.

Example: whereNull()

SQL Query:

select * from `users`

where `email_verified_at` is null

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->whereNull('email_verified_at')

->get();

dd($users);

}

}

Example: 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\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->whereNotNull('email_verified_at')

->get();

dd($users);

}

}

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Eloquent whereBetween() Query Example

Read Now →

Laravel Eloquent whereRaw Condition Example

Read Now →

Laravel Multiple Where Condition Example

Read Now →

Laravel Eloquent WhereNotIn Query Example

Read Now →

Laravel Eloquent WhereIn Query Example

Read Now →

Laravel WhereIn() and WhereNotIn() with Subquery Example

Read Now →

Laravel Where Condition with Two Columns Example

Read Now →

Laravel Where Clause with date_format() Example

Read Now →

Laravel Where Clause with MySQL Function Example

Read Now →

Laravel Query Builder Where Exists Example

Read Now →