Issue
I am trying to update a table column with form data.
The form will pass the values in the form of an array as shown below.
Now I need to fill the existing table with data from the array. Something like first data into the first row.
$infos = data::where('name', '=', 'abc')->select('*')
->orderBy('id')->get();
$i = 0;
while($i < count($infos)){
foreach ($infos as $info) {
$info[$i]->subject = $request->subject[$i] ? $request->subject[$i] : null;
$info->save();
}
}
Solution
After seeing the comment reply from the OP. Just use this method:
$infos = Data::where('name', 'abc')->orderBy('id')->get();
foreach($infos as $key => $info){
$info->subject = $request->subject[$key];
$info->save();
}
Answered By - Wahyu Kristianto
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.