PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Laravel query showing wrong data while use where and orWhere clause

 February 04, 2022     eloquent, laravel     No comments   

Issue

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?


Solution

use where not in

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


Answered By - Yazan Fouad Aldbaisy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing