Validation does not return array with errors

1

I'm trying to use laravel validation to validate a form, but I'm not getting the array of errors

Controller

use Illuminate\Http\Request;
class Curriculos extends Controller {
public function store(Request $request){

    $this->validate($request, [
      'nome' => 'required|min:5'
    ]);

    $curriculos = $request->all();

    $curriculos['dt-nascimento'] = str_replace('/', '-', $curriculos['dt-nascimento']);
    $curriculos['dt-nascimento'] = date('Y-m-d', strtotime($curriculos['dt-nascimento']));

    $curriculos['dt-inicio'] = $this->formatDate($curriculos['dt-inicio']);

    $curriculos['dt-conclusao'] = $this->formatDate($curriculos['dt-conclusao']);

    $curriculo = new Curriculo;

    if($curriculo->create($curriculos)){
      return redirect('/');
    }


}

View

 <?php var_dump($errors->all()); ?>
 <form class="" action="{{url('/api/send')}}" method="post">
   @csrf
  ......

Var_dump () result

 array(0) { } 
    
asked by anonymous 31.07.2018 / 16:27

1 answer

2

When using routes defined in api.php, as mentioned by Luhan Salimena the middleware group ShareErrorsFromSession is not applied (see configuration in Kernel.php).

View The $ errors variable is not passed to the

See the documentation at link

The routes in api.php are suitable for requests via Ajax in this case by default when there is a validation error will get a Json response with the code 422 with all errors found.

I suggest you change your route to web.php which seems to be more appropriate for you.

    
31.07.2018 / 16:50