Set the Header to accept only 'application/json' format as response.
Also, please show the UserStoreRequest file, did you always return true at the function authorize?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, Laravel - 8.x PHP 7.4
I'm using api routes and also request validation However when the request fail, laravel is returning error 200 and welcome view
USER STORE REQUEST:
public function rules()
{
return [
'name' => 'required|max:100',
'email' => 'required|email|unique:users,email',
'password' => 'required|max:50',
];
}
// My controller method
public function store(UserStoreRequest $request)
{
// This fail the request and return status 200
try {
$this->repository->create($request);
return response()->json(['message' => 'User created!'], 201);
} catch (\Throwable $th) {
return response($th->getMessage(), 400);
}
}
If I send a post here with wrong params I got status 200 like this print: https://prnt.sc/1ru7n1u I should got status code 422
What should I do to return the correct status code with validation error message?
@Thavo You set the wrong key at the header.
Change the "content-type" to "Accept"
Please or to participate in this conversation.