How can I do this validation within the request class, this part corresponds to a controller method
public function store(vendedorrequest $request)
{
$validator = \Validator::make($request->all(), [
'nombre' => 'required',
'nombre.required'=>'Rellena el campo nombre',
]);
if ($validator->fails()) {
return response()->json($validator->errors(), 422);
}
}
this is the request where I want to apply the make method, but I only know how to do it directly from the controller
public function rules()
{
return [
'documento'=>'required|numeric|unique:vendedores,documento',
'correo'=>'required|email|unique:vendedores,correo',
'nombre'=>'required',
'direccion'=>'required',
];
}
Validation in Form Request
Create a FormRequest
You can override the method
failedValidation
if you want to customize the response:Note that you will have to import those classes in the form requirements in order to use them by adding these lines above: