Laravel Eloquent whereNotNull() Query Example

By Hardik Savani | July 27, 2020 | Category : Laravel


If you need to see example of laravel wherenotnull example. This post will give you simple example of laravel where not null example. i explained simply about wherenotnull laravel eloquent example. you will learn 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 and laravel 7 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: 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);

}

}

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);

}

}

I hope it can help you...




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: