Wherenull Laravel Query Builder Example

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Wherenull Laravel Query Builder Example

Today now in this example,I will show you how to use whereNull query in laravel application .We can simply use to whereNull query in our controller. So we are see here a easy example of where null or empty in laravel application.

So i will let you know how we can write query for where null and also where not null condition. Now here i will write a core SQL query and then convert it into laravel query builder by using db. So just need to 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);
}

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →