¿Puede alguien explicarme este código?
Publicado por Lucas (46 intervenciones) el 06/06/2020 22:40:54
Me ayudaron con este código, pero no logro entenderlo muy bién el por qué de la array multidimensional.... quizás alguien de qui podría ayudarme, acá va: (linea 6 y 7 de la función Store)
Esta hecho con el framework laravel, y Laravel Collective.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{!! Form::open(['method'=>'POST', 'route' => 'objetivos.store']) !!}
<table class="table">
<tr>
<th>Fecha</th>
@foreach($objetivos as $obj)
<th>Objetivo {{$obj->id}}</th>
@endforeach
</tr>
<tr>
<td>
{!!Form::date('fecha')!!}
</td>
@foreach($objetivos as $obj)
<td>
{!!Form::time('tiempo[]')!!}
{!!Form::hidden('obj_id[]', $obj->id)!!}
</td>
@endforeach
</tr>
<tr>
<td colspan="4">{!!Form::submit('Agregar datos de hoy')!!}</td>
</tr>
</table>
{!! Form::close() !!}
1
2
3
4
5
6
7
8
9
10
11
public function store(Request $request)
{
foreach($request->tiempo as $key => $value){
objetivosApp::create([
'fecha' => $request['fecha'],
'obj_id' => $request['obj_id'][$key], // aquí deberás indicarle el índice que coincida con el del input sobre el que estás iterando
'tiempo' => $value // este es el input sobre el que iteras, así que solo asígnale el valor
]);
}
return redirect('/');
}
Esta hecho con el framework laravel, y Laravel Collective.
Valora esta pregunta


0