Home > Back-end >  Laravel Eloquent WHEREIN with string
Laravel Eloquent WHEREIN with string

Time:06-16

I have a string inside $loc_name1='Kochi','Hydarabad','Buwaneswar';

and i have a laravel query

 $employees = DB::table('audit_employee_basics')
                    ->select('audit_employee_basics.id as empid','emp_name','emp_code','designation_name','emp_company_email_id','emp_contact_number','emp_gender','emp_location'
                            ,'department_name','emp_joining_date','fk_emp_previous_exp','image') 
                ->join('audit_department', 'audit_employee_basics.emp_fk_dep', '=', 'audit_department.id')
                ->join('audit_employee_skillset', 'audit_employee_skillset.fk_emp_id', '=', 'audit_employee_basics.id')
                  ->join('audit_designation', 'audit_designation.id', '=', 'audit_employee_basics.emp_fk_des_id')
                ->whereIn('audit_employee_basics.emp_location', [$loc_name1])
               
                   -> distinct()
                 ->get(); 

which is not working for me.and if i change ->whereIn('audit_employee_basics.emp_location', ['Kochi','Hydarabad','Buwaneswar']) is working for me.Any help would be highly appreciated

CodePudding user response:

whereIn expects the second argument to be an array. You can change your script as :

->whereIn('audit_employee_basics.emp_location', explode(',', $loc_name1))
  • Related