Laravel 5.5 I'm using the validations as follows, directly in the controller
$this->validate($req,[
'nome' => 'required|min:10',
'cpf' => 'required|size:14',
'agencia' => 'required',
],[
'nome.required'=>'Preencha um nome',
'nome.min'=>'Campo nome: Minimo de 10 Caracteres',
'cpf.size' => 'Preencha corretamente o CPF',
'required' => 'Campo Necessário',
]);
And in the views are either in list or in the inputs field the error messages:
@if(count($errors) > 0 )
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
I would like to know how to use make: request and put in the functions of rules and messages because when I put, when submitting the form, an authentication error occurs in the save controller I place a request and import it
public function salvar(TesteValidaRequest $req){...}
in the request file
public function rules()
{
return [
'nome' => 'required|min:10'
];
}
public function messages()
{
return [
'nome.required' => 'Necessário preencher um nome',
'nome.min' => 'Nome minimp de 10 Caracteres',
];
The doubt is that an unauthorized action error is appearing when submitting the form, even authorize () returning false as it speaks in the documentation, and I would also like to know if to pass the errors to the views is the same way, I tried through the documentation and could not.