Home > Net >  Laravel query showing wrong data while use where and orWhere clause
Laravel query showing wrong data while use where and orWhere clause

Time:02-03

Users::where('application_ID', '=', $request->application_ID)
->where(function ($query) {
    $query->where('app_status','!=','')
          ->orWhere('app_status','!=','Accept')
          ->orWhere('app_status','!=','Reject')
          ->orWhere('app_status','!=','Comm Accept')
          ->orWhere('app_status','!=','Comm Reject');
})->get();

Output:

select * from `user` where `application_ID` = '0320120332330' and (`app_status` != 'Accept' or `app_status` != 'Reject' or `app_status` != 'Comm Accept' or `app_status` != 'Comm Reject')

In the above query if in my table I have app_status = Accept, Reject, Comm Accept and Comm Reject then the query return all record related to application_ID = '0320120332330' but I have already mention that if app_status != Accept, Reject, Comm Accept and Comm Reject then again it return all record. I don't know why?

CodePudding user response:

use where not in

Users::where('application_ID', '=', $request->application_ID)
->whereNotIn('app_status', ['', 'Accept', 'Reject', 'Comm Accept', 'Comm Reject'])->get();
  •  Tags:  
  • Related