Laravel 7/6 Where Clause with Function Example
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": "[email protected]"
+"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": "[email protected]"
+"type": 1
+"point": 101
+"remember_token": null
+"created_at": "2020-02-04 00:00:00"
+"updated_at": null
}
]
It will help you.....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial