search

Home  >  Q&A  >  body text

Laravel Eloquent uses strings for WHEREIN operations

I have a string in it $loc_name1='Cochin','Haydaraba','Bhuvaneshwar';

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();

This doesn't work for me. If I change ->whereIn('audit_employee_basics.emp_location', ['Kochi','Hydarabad','Buwaneswar']) is working for me. Any help would be greatly appreciated

P粉388945432P粉388945432237 days ago452

reply all(1)I'll reply

  • P粉198749929

    P粉1987499292024-03-28 17:03:24

    whereIn Expects the second parameter to be an array. You can change the script to:

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

    reply
    0
  • Cancelreply