i have a simple registeration form i use this validation for creating u new user
$validator = Validator::make($request->all(), [
'first_name' => ['required'],
'last_name' => ['required'],
'phone' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', ],
]);
if ($validator->fails()) {
return response()->json(['message' => 'Errors!','errors'=>$validator->errors()], 500);
}else{
return response()->json(['message' => 'User registered successfully'], 201);
}
now i need to make a vidation rule to combine last and first name together and validate max chars
2
Answers
Write Laravel Custom Validation Rules
and in the validation rule
i would first add the full_name entry to the request object, and then i would validate with the built in validation rules (either max or between).