In this article, we will see the laravel 9 whereNull / whereNotNull query example. In laravel 9 additional where clauses provide many built-in where methods. So, we will learn how to write queries for whereNull and whereNotNull methods in laravel 9. Also, laravel 9 provides the same method as orWhereNull and orWhereNotNull.
The whereNull() method is used to check the value of the given column is NULL and The whereNotNull() method is used to check the value of the given column is not NULL. Also, we will see examples of SQL query and syntax of IS NULL and IS NOT NULL.
So, let's see a whereNull query in laravel 9 and a whereNotNull query in laravel 9.
The IS NULL is used to check the empty value.
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
In this example, we will retrieve all customers with a NULL value in the Address field.
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;
In laravel whereNull() function add a column to check the condition.
whereNull(Column Name);
In this example, we will retrieve all records with the updated_at column value being NULL.
$users = DB::table('users')
->whereNull('updated_at')
->get();
The IS NOT NULL is used to check the non-empty value.
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
In this example, we will retrieve all customers with a value in the Address field.
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;
In laravel whereNotNull() function add a column to check the condition.
whereNotNull(Column Name);
In this example, we will retrieve all records from the user's table with the updated_at column value not NULL.
$users = DB::table('users')
->whereNotNull('updated_at')
->get();
You might also like:
In this article, we will explore the integration of OpenAI into Laravel versions 8, 9, and 10. Our focus will be on unde...
Feb-06-2023
In this post we will learn how to add watermark on image in laravel 8. here we will see example of laravel 8 add waterma...
Jun-23-2021
In this article, we will see an example of laravel 8 custom email verification. Many web applications require users...
Dec-29-2021
In this article, we will see how to validate phone numbers using jquery. We will learn different methods of validat...
Oct-24-2022