Laravel Eloquent having() Query Example

10-Apr-2023

.

Admin

Laravel Eloquent having() Query Example

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

#Laravel 7

#Laravel

#Laravel 6