I am posting on Postman to my api route (in api.php) and when the data fails in validation, it returns me the errors in 200 response under this:
The above response is when I try:
{
$valid = validator($request->only('email', 'password'), [
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6',
]);
if ($valid->fails()) {
$jsonError=response()->json($valid->errors()->all(), 400);
return \Response::json($jsonError);
}
}
However, when I try the one in the documentation like below, it returns me to the view (laravel welcome page), something like return back()
$request->validate([
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6',
]);
And the data I post is:
email: ''
password: ''
// also tried with and without header
Content-Type: application/json