10-Apr-2023
.
Admin
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
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