M
M
marq2022-01-09 13:27:01
SQL
marq, 2022-01-09 13:27:01

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
61dab697a4b67820268286.png
Namely, the "Points" field,
61dab6e6ca07e011406778.png
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
61dab7ae07827179679829.png
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);


It looks like I did some kind of garbage, but then I can’t figure out how to fill in the "points" fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2022-01-09
@rozhnev

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();
}

PHP online test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question