Laravel Eloquent where null and where not null query

0

How we can find the NULL and Not NULL records using the Laravel. Laravel provides a whereNull for finding the NULL records and whereNotNull for finding the NOT NULL records. Today, we are going to learn both methods with example.

Laravel Eloquent where null

1 ) whereNull

First of all, We are going to learn whereNull method for finding the NULL records. Let’s see how we can find the NULL records from database using the Laravel Eloquent like.

DB::table('company')
    ->whereNull('description')
    ->get();

/*
* My SQL Query
*/
select * from comapny where description IS NULL

2 ) whereNotNull

Let’s see how we can find the NOT NULL records form the database using the Laravel with example.

DB::table('company')
  ->whereNotNull('description')
  ->get();
/*
* My SQL Query
*/
select * from comapny where description IS NOT NULL

I hope this article useful for you. Please let us know if anything was missing or wrong by comment.

Share.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.