Laravel eloquent, query based on where AND OR inside it

1157 0 0 0

Last Updated : 2024-06-25 19:02:19

Some times you will need to create an eloquent where clause and inside that where you may need to add extra or where claused

Model::where(function ($query) use ($a,$b) {
$query->where('a', '=', $a)
->orWhere('b', '=', $b);
->where(function ($query) use ($c,$d) {
$query->where('c', '=', $c)
->orWhere('d', '=', $d);

//------------------------------ Another Example
$committeeTest = CommitteeModel::where("id","!=", $id)->where(function($q) use($name, $acronym){


$allCommitteeDocs = GovernmentResponsesModel::where('date', '>=', "$dateLimit")->with(['committee'])
'committee',function($billQ2) use ($memberId){
'favorites',function($favoritesQ) use ($memberId) {
->whereIn('entity_type',['committee', 'provincialcommittee'])
/* ->where(function($committeeQ) {
}) */

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .