mardi 24 juillet 2018

Update multiple rows in Database Table

I want to update multiple rows. Here is my controller file:

$ids = [$request->get('com_id')];
$name = [$request->get('com_name')];
$stat = [$request->get('com_status')];
$now = Carbon::now();
$count = count($ids);
$thiss=$request->validate(
    ['com_name' => 'required',
     'com_status' => 'required'
    ]);
   // $i=0;
   for ($i=0; $i <$count ; $i++) { 
    $companies = companies::find($ids[$i][0]);
       companies::where('id',$ids[$i][0])
    ->update(['company_name' => $name[$i][0],
             'status' =>  $stat[$i][0]
             ]);

but in my code, Just the 1st row is being updated. what can I do for updating multiple rows with array index number?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire