Laravel Eloquent having() Query Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

2338

21-07-2020


Hello Friend,

In this blog, I will teach you 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. The having method's signature is similar to that of the where method.

The use of having query in laravel used to same as where clause method. You may pass multiple arguments to the groupBy method to group by multiple columns.

Here i will give you two example for laravel having query. So let's see the bellow example.

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();

}

It will help you...


Recommended Posts