John Davidson

php - Execute Query after value from Multiselect in Laravel

0 comments
Message:


Hi I am working in Laravel.


I need to select all rows from databse with selected company_id. In form company_id is multi select


This is what I have done


$data = $request->All();
$notifyTo = $data['notify_to']; /**value from multiselect which is an array**/
foreach($notifyTo as $noTo => $value){
$user = User::all()->where('company_id', "=", $value)->where('status', "=", 1);
}
print_r($user); exit;

here $data['notify_to'] is the value from multiselct , which is an array of company_id Array ( [0] => 11 [1] => 22 [2] => 33 )


Table Structure


| id | name | company_id | status |
-----------------------------------


My Answer:
all();
$company_ids = $data['company_id'];

$users = User::whereIn('company_id', $company_ids)->get();

return $users;

Rate this post

3 of 5 based on 9369 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us