if one row is checked if($isset->has('test')) returns all rows. I only want to save the marked rows.
My view file:
<tbody>
@foreach($match->homeTeam->players as $player)
<tr>
<th scope="row"></th>
<td class = "col-md-6" name = "player[]" value = ""> </td>
<td align="center" class= "col-md-2"><input class="form-check-input" type="checkbox" name="test" value=""></td>
<td class = "col-md-2"><input name="minutes[]" class="form-control"></td>
<td class = "col-md-2"><input name="goals[]" class="form-control"></td>
</tr>
@endforeach
</tbody>
Controller:
public function storeMatchFacts(Match $match, Request $request, Match_fact $match_fact, Player $player)
{
$home_team_players=$match->homeTeam->players;
if($isset->has('test')) {
foreach ( $home_team_players as $k => $p ) {
$data[] = [
'match_id' => $match->id,
'player_id' => $player->id,
'minutes' => $request['minutes'][$k],
'goals' => $request['goals'][$k]
];
}
dd($data);
} else {
dd('error');
}
Aucun commentaire:
Enregistrer un commentaire