Laravel Eloquent uses strings for WHEREIN operations
P粉388945432
P粉388945432 2024-03-27 18:41:43
0
1
428

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粉388945432
P粉388945432

reply all(1)
P粉198749929

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

->whereIn('audit_employee_basics.emp_location', explode(',', $loc_name1))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!