Laravel, validator with multiple fields and {{old}}

0

I have this code with $ n form fields. I am not able to use the validator; {

public function salvar()
          {
    $n =Request::input('campos');
    for($i=1; $i < $n; $i++){

    $pontosa =Request::input('pontosa'.$i);
    $pontosb =Request::input('pontosb'.$i);
    $validator = Validator::make(
      [ "'pontosa'.$i" => $pontosa,
        "'pontosb'.$i" => $pontosb
      ],
      [
        'pontosa.$i' => 'required|numeric',
        'pontosb.$i' => 'required|numeric'
      ]
    );
    if($validator->fails()){
      return redirect()->action('UsersController@lista');
    }
    $pontuacao =new Listadepontos();
    $pontuacao->pontosa = $pontosa;
    $pontuacao->pontosb = $pontosb;
    $pontuacao->save();
}}

I also can not keep data populated with {{old}} because fields are generated from a foreach

name="<?php echo 'pontosa'.$n; ?>"

I'm not getting it right. I already tried several formulas to do the {{old}} cm variables but I could not!

<form action="{{ action('UsersController@salvar') }}" method="POST">
  <table  class="table table-striped table-bordered table-hover table-inverse" style="text-align:center">
  <input type="hidden" name="_token" value="{{{ csrf_token() }}}">
$n=1;
 foreach($jogos as $j){ ?>
<tr>
<input type="text" size="2" maxlength="2" name="<?php echo 'pontosa'.$n; ?>" value="{{old????}}" > </td>

<input type="text" size="2" maxlength="2" name="<?php echo 'pontosb'.$n; ?>" value="{{old???}}" ></td>
      </tr>

<?php $n++; } ?>


    <input type="hidden" name="campos" value="<?php echo $n;?>">
    
asked by anonymous 27.09.2017 / 14:57

0 answers