0
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?

1
  • 1
    You have multiple orWhere on the same column with !=, so you get every record. if it is "Accept" it is not "Reject" so the record is in your results... Basically 4 of the orWhere statements are always true Commented Feb 2, 2022 at 6:59

1 Answer 1

1

use where not in

Users::where('application_ID', '=', $request->application_ID)
->whereNotIn('app_status', ['', 'Accept', 'Reject', 'Comm Accept', 'Comm Reject'])->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.