In this Laravel Validator, what is the correct code with variable?

0

In this Validator of Laravel , what is the right code with variable?

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');
    
asked by anonymous 27.09.2017 / 20:03

1 answer

1

I use this as part of the login code :

public function logar(Request $request)
{

    $credenciais = $request->only('email', 'senha');
    $validator = Validator::make($credenciais, [
        'email' => 'required',
        'senha' => 'required',
    ]);

    if($validator->fails()) 
    {
        return response()->json([
            'error' => true, 
            'mensagem'=> 'Formato de dados inválidos', 
            'data'=> $credenciais
        ], 401);
    }
}
    
27.09.2017 / 20:14