Are you sending the request with an json header? https://carldesouza.com/how-to-set-content-type-to-application-json-in-postman/
Sep 26, 2022
4
Level 5
How to show Custom Request errors in API
Hello, I am using Laravel 9 for building API.
In registration, I have created a request file named 'RegisterRequest.' In that, I have written some rules. Like the below:
class RegisterRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|min:3|max:50',
'email' => 'required|email:rfc,dns|unique:users',
'password' => 'required|confirmed|min:6'
];
}
}
In my AuthController, how will I get that error validation if it fails? In postman, it's redirecting to the home route. I want to show them in the front end.
public function register(RegisterRequest $request)
{
if ($request->fails()) {
return "Error";
}
dd($request->validated());
}
Please or to participate in this conversation.