Wherenull Laravel Query Builder Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

3934

06-01-2020


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...


Recommended Posts