0

I have two fields in my table, contact_name and company. for searching purposes, I am using this. I need to search by using contact_name and company. Now one is working fine, but I need to add a second field in the same where condition. How do I add this?

if(isset($input['dsr_commonsearch']) && $input['dsr_commonsearch']){
        $query->where('dsr.contact_name','dsr.company','=', $input['dsr_commonsearch']); 
    }
BDL
  • 21,052
  • 22
  • 49
  • 55
anu
  • 3
  • 2
  • What is `$query` ? the QueryBuilder? – Hamza Abdaoui Dec 22 '20 at 13:25
  • if(isset($input['dsr_commonsearch']) && $input['dsr_commonsearch']){ $query->where('dsr.contact_name','dsr.company','=', $input['dsr_commonsearch']); } this is our query two felids are contact_name and company Hamza Abdaoui – anu Dec 22 '20 at 13:28
  • Does this answer your question? [How to Create Multiple Where Clause Query Using Laravel Eloquent?](https://stackoverflow.com/questions/19325312/how-to-create-multiple-where-clause-query-using-laravel-eloquent) – Hamza Abdaoui Dec 22 '20 at 13:29

1 Answers1

0

Try using orWhere as below:

if(isset($input['dsr_commonsearch']) && $input['dsr_commonsearch']){
    $query->where('dsr.company','=', $input['dsr_commonsearch'])->orWhere('dsr.contact_name','=', $input['dsr_commonsearch']); 
}
  • is it working and how to add like instead of = because some times we will enter with sapce Hamza Abdaoui – anu Dec 22 '20 at 13:32
  • is it working and how to add like instead of = because some times we will enter with space Zohaib Shah – anu Dec 22 '20 at 13:38
  • @anu You can replace '=' with 'like' and in third argument append '%' in string – Zohaib Shah Dec 22 '20 at 13:57