Laravel Eloquent exists() and doesntExist() query Example

10-Apr-2023

.

Admin

Laravel Eloquent exists() and doesntExist() query Example

Hello Friend,

In this blog, I will show you exists query or doesntExists query in laravel application. We will learn laravel exists or doesntExist eloquent query.

Instead of using the count


method to determine if any records exist that match your query's constraints, you may use the exists and doesntExist methods.

If you check users without count() then you can use exists or doesntexists query in laravel application.

exists() query used to any rows exist for the current query and doesntExist() query used to no rows exist for the current query.

Example 1

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

return DB::table('users')->where('is_active', 1)->exists();

}

Example 2

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

return DB::table('users')->where('is_active', 1)->doesntExist();

}

It will help you...

#Laravel 7

#Laravel

#Laravel 6