In this tutorial, we will see how to use having query in laravel application. We will learn laravel eloquent having query example.

The groupBy and having methods may be used to group the query results.

Given below are two examples for laravel having query. 



Example 1 : Query

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = DB::table('users')
                ->having('salary', '<', 10000)
                ->get();
}



Example 2 : having with groupBy

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = DB::table('users')
                ->groupBy('name', 'email')
                ->having('id', '>', 1)
                ->get(); 
}


I hope this example helps you.