Livewire multi parent:child form + eloquent checkbox normalization
Tips on this? Wanted to know if there's a better way to normalize the checkboxes:
public function salvar(): RedirectResponse
{
$validatedData = $this->validate();
foreach ($validatedData['ofertas'] as $oferta) {
$newOferta = Oferta::create($oferta);
foreach ($oferta['docentes'] as $docente) {
DocenteOferta::create([
...$docente,
'compartilhada' => isset($oferta['compartilhada']),
'topico' => isset($oferta['compartilhada']),
'oferta_id' => $newOferta->id
]);
}
foreach ($oferta['ofertas_semana'] as $oferta_semana) {
OfertaSemana::create([
...$oferta_semana,
'oferta_id' => $newOferta->id
]);
}
}
return redirect()
->route('ofertas.listar')
->with('success', 'Oferta(s) cadastrada(s) com sucesso!');
}
I don't understand what you mean when you say normalize the checkboxes => where are the checkboxed ? I don't understand where are the boolean values.
To retrieve the boolean values from a form, I do like this.
$model->is_ok = $this->boolean($request->is_ok);
Please or to participate in this conversation.