Wherenull Laravel Query Builder Example
Hi Guys,
In this example,I will learn you how to use whereNull query in laravel .you can simply use to whereNull query in your controller. we are so easy example where null or empty in laravel.
i will let you know how you can write query for where null and where not null condition. here i will write core SQL query and then convert it into laravel query builder using db. So just see bellow example and see how it is works.
Example 1
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$news = \DB::table('news')
->whereNull('country_id')
->get();
dd($news);
}
Example 2
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$posts = \DB::table('posts')
->whereNull('body')
->get();
dd($posts);
}
Example 3
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$users = User::whereNull('updated_at')->get();
dd($users);
}
It will help you...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial