i'm trying to post match information about each player.
match_facts schema:
Schema::create('match_facts', function (Blueprint $table) {
$table->id();
$table->uuid('match_id');
$table->uuid('player_id');
$table->integer('minutes')->nullable();
$table->integer('goals')->nullable();
$table->boolean('yellowCard');
$table->boolean('redCard');
$table->timestamps();
});
main goal is to post all players to database which have checkbox "in squad"
Now doesn't matter if checkbox is cheked or not, record for each player is created.
Also problem with booleans. The request does not retrieve them.
Here is my html code:
@foreach($match->homeTeam->players as $player)
<tr>
<th scope="row">{{$player->id}}</th>
<td class = "col-md-6" name = "player[]" value = "{{$player->id}}">{{$player->name}} {{$player->surname}}</td>
<td align="center" class= "col-md-2"><input class="form-check-input" type="checkbox" name="squad[]" 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>
<td align="center" class= "col-md-2"><input class="form-check-input" type="checkbox" name="yellowCard[]" value=""></td>
<td align="center" class= "col-md-2"><input class="form-check-input" type="checkbox" name="redCard[]" value=""></td>
</tr>
@endforeach
</tbody>
</table>
and controller:
if (isset($request->squad)) {
foreach ( $match_players as $k => $p ) {
$data[] = [
'match_id' => $match->id,
'player_id' => $p->id,
'minutes' => $request['minutes'][$k],
'goals' => $request['goals'][$k],
'yellowCard' => $request['yellowCard'][$k],
'redCard' => $request['redCard'][$k],
];
}
}
if(count($match_players)>0){
Match_fact::insert( $data );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…