Laravel 7/6 Where Clause with Function Example

Feb 17, 2020

.

Admin

This tutorial is focused on laravel where with function. if you want to see example of where with function laravel then you are a right place this example will help you how to use where clause with function in laravel. you can see where with function laravel. You just need to some step to done laravel where function parameter.

Example :


SQl Query :

select * from `users` where `type` = ? or (`type` = ? and `point` > ?)

Laravel Query :

 

public function index()

{

$users = DB::table('users')

->where('type', 2)

->orWhere(function($query) {

$query->where('type', 1)

->where('point', '>', 100);

})

->get();

dd($users);

}

Output :

#items: array:2 [?

0 => {#323 ?

+"id": 1

+"name": "admin"

+"email": "admin@gmail.com"

+"type": 2

+"point": 50

+"remember_token": null

+"created_at": "2019-12-28 00:00:00"

+"updated_at": null

}

1 => {#326 ?

+"id": 4

+"name": "jd"

+"email": "jd@gmial.com"

+"type": 1

+"point": 101

+"remember_token": null

+"created_at": "2020-02-04 00:00:00"

+"updated_at": null

}

]

It will help you.....

#Laravel 6

#Laravel

#Laravel 7