0
I have this code with $n form Fields. I’m not getting to use 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();
}}
Nor can I keep the data filled with {{old}} because the fields are generated from a foreach
name="<?php echo 'pontosa'.$n; ?>"
I’m not getting it right. I’ve tried several formulas to do {{old}} cm variables but I couldn’t!
<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;?>">
Show the form?
– novic
I edited with form
– Dan Even
Possible duplicate of In this Laravel Validator, what is the right syntax? With variable
– novic