0
Follows my AuthRequest.php
:
<?php
namespace App\Http\Requests;
use Illuminate\Http\Request;
use App\Rules\CpfValidacao;
class AuthRequest extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|min:1|max:255',
'cpf' => ['required', 'min:1', 'max:11', new CpfValidacao],
'name' => 'required|min:1|max:255',
'password' => 'required|min:8|max:255'
//'profile_picture_path' => 'required|min:1|max:255'
];
}
/*** Novas mensagens ***/
public function messages()
{
return [
'email.required' => 'Campo email requerido!',
'email.min' => 'Campo email deve ser de no mínimo 1 caracter!',
'email.max' => 'Campo email deve ser de no máximo 255 caracteres!',
'cpf.required' => 'Campo cpf requerido!',
'email.min' => 'Campo cpf deve ser de no mínimo 1 dígito!',
'email.max' => 'Campo cpf deve ser de no máximo 11 dígitos!',
'name.required' => 'Campo name requerido!',
'name.min' => 'Campo name deve ser de no mínimo 1 caracter!',
'name.max' => 'Campo name deve ser de no máximo 255 caracteres!',
'password.required' => 'Campo password requerido!',
'password.min' => 'Campo password deve ser de no mínimo 8 caracteres!',
'password.max' => 'Campo password deve ser de no máximo 255 caracteres!',
];
}
}
My doubt is here:
/*** Registra usuário ***/
public function register(AuthRequest $request)
{
/*** validação de parâmetros ***/
$validator = Validator::make($request->all(), [
'email' => 'required|min:1|max:255',
'cpf' => ['required', 'min:1', 'max:11', new CpfValidacao],
'name' => 'required|min:1|max:255',
'password' => 'required|min:8|max:255'
//'profile_picture_path' => 'required|min:1|max:255'
]);
if($validator->fails()){
$errors = $validator->erros();
return response()->json(['error' => true, $errors], 422);
}
/*** fim ***/
How I do the new implementation?
laravel 6.2
Question doesn’t say what you want?
– novic
I don’t understand very well, you want to use Authregisterrequest.php to validate user creation?
– Lucas Pace