Answer the question
In order to leave comments, you need to log in
How to fill some table fields in a form in laravel?
Good afternoon, there is an html table with data from the database and some fields need to be filled in separately
Namely, the "Points" field,
This is how the database itself looks like.
I wanted to fill them in by the team_id field and combined two arrays received from the form
The code of the Controller and Model itself:
$team_id = $request->input('team_id');
$point = $request->input('points');
foreach ($point as $key => $value) {
$points[]['points'] = $value;
}
foreach ($team_id as $key => $value) {
$teams_id[]['team_id'] = $value;
}
$data = array_map('array_merge', $teams_id, $points);
Admin::setPointsStage_1($turnir_id, $data);
return DB::table('stage_1')->where('tournament_id', $turnir_id)->update($data);
Answer the question
In order to leave comments, you need to log in
DB::beginTransaction();
try {
foreach ($data as $d) {
DB::table('stage_1')
->where('tournament_id', $d['tournament_id'])
->where('team_id', $d['team_id'])
->where('group_id', $d['group_id'])
->update(['points' => $d['points']]);
}
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question