Laravel whereNull & whereNotNull Eloquent Query with Example


Share:
Published By: Admin, Published On: Apr 30, 2021, Category: Laravel

Hello Friends,

Now let's see example of how to use whereNull() and whereNotNull() in laravel. This is a short guide on laravel if whereNull(), whereNotNull(). We will use how to use whereNull() and whereNotNull() in laravel. Here you will learn how to use whereNull() and whereNotNull() in laravel. Let's get started with how to whereNull() and whereNotNull() use in laravel.

Here i will give you many example and understand how works this whereNull and whereNotNull functions one by one in laravel.

Example whereNull():

The whereNull method verifies that the value of the given column is NULL.

/**
    * Write code on Method
    *
    * @return response()
*/
public function index()
{
    $contacts = Contact::whereNull('updated_at')
                        ->get()
                        ->toArray();
    dd($contacts);
}
Output:
array:5 [▼
  0 => array:7 [▼
    "id" => 1
    "name" => "test"
    "email" => "test@gmail.com"
    "phone" => "98845646"
    "message" => "test"
    "created_at" => "2021-04-29T09:48:23.000000Z"
    "updated_at" => ""
  ]
]
Example whereNotNull():

The whereNotNull method verifies that the column's value is not NULL.

/**
    * Write code on Method
    *
    * @return response()
*/
public function index()
{
    $contacts = Contact::whereNotNull('updated_at')
                        ->get()
                        ->toArray();
    dd($contacts);
}
Output:
array:5 [▼
  0 => array:7 [▼
    "id" => 1
    "name" => "test"
    "email" => "test@gmail.com"
    "phone" => "98845646"
    "message" => "test"
    "created_at" => "2021-04-29T09:48:23.000000Z"
    "updated_at" => "2021-04-29T09:48:23.000000Z"
  ]
]

It will help you....

Share: