0
I’m trying to input a lot of data using FOR but it’s not working. The impression is that he is not getting the data from FOR?
The expectation is that this happens:
ID|id_proposta|id_produto|quantidade|valor|total
1 |8 |1 |2 |250 |2000
2 |8 |2 |9 |300 |1000
3 |8 |3 |7 |150 |9000
4 |8 |4 |8 |200 |40000
5 |8 |5 |3 |290 |25000
Follows the code:
Controller
public function create()
{
$dadosForm = $this->request->all();
$proposta = $this->proposta;
$proposta->save([$dadosForm]); //salvo uma parte do for
$proposta_id = $proposta->id; //pego o ID Salvo
$count = $this->ensaios->max('id');
$proposta_ensaios = $this->proposta_ensaios; //Essa parte fica em cinza parece que nao esta funcionando
for($i=0;$i<=$count;$i++){
$proposta_ensaios = new PropostaEnsaios();
$proposta_ensaios->id_proposta = $proposta_id; //Aproveito o ID Salvo
$proposta_ensaios->id_produto = $i;
$proposta_ensaios->quantidade = $this->request->get('quantidade_'.$i);
$proposta_ensaios->valor= $this->request->get('valor_'.$i);
$proposta_ensaios->total = $this->request->get('total_'.$i);
$proposta_ensaios->save([$dadosForm]);
}
quantidade
cannot come blank is what it says error. So has a problem in:$this->request->get('quantidade_'.$i);
– rray
Yes if you look a little further down it is not only the amount this coming in blank value and total tb in error are like "null" Without the for works but saves only 1 record and I have almost 30
– Shaolin Fantastic
You need to see if the values in the inputs can be given
undefined index: ...
Comments on thesave()
and make aecho '<pre>'; print_r($proposta_ensaios);
– rray
[quantity] => [value] => [total] =>
– Shaolin Fantastic
In place of
$this->request->get('quantidade_'.$i)
shouldn’t be then$dadosForm['chave']
?– rray
That’s right @rray! Comments your reply to me positive!
– Shaolin Fantastic
I think you better (if you want) create the answer I imagine you can give more details about how you solved the problem.
– rray
Hard when I comment I can only close the question after 2 days but that’s okay!
– Shaolin Fantastic