I've been working on a Laravel 9 API with validation. On my dev system, using Windows/Apache/PHP 8.1, the POST requests return a 422 with the json validation errors. My request header includes "Accept: application/json".
{
"message": "The name field is required.",
"errors": {
"name": [
"The name field is required."
]
}
}
I have deployed the code to the Test system, which uses Linux/Apache/PHP 8.1. When I run the exact same request, I just get a 422 error without the json response.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>422 Unprocessable Content</title>
</head><body>
<h1>Unprocessable Content</h1>
<p>The server understands the media type of the
request entity, but was unable to process the
contained instructions.</p>
</body></html>
Here is my code but as it works on the my Dev system I can't think how it's wrong.
StoreClientRequest.php
public function rules()
{
return [
'name' => 'required|string|max:255'
];
}
ClientAPIController.php
public function store(StoreClientRequest $request)
{
$client = Client::create($request->all())->fresh();
return (new ClientResource($client))->response()->setStatusCode(201);
}
Since it's working on my localhost I don't believe it is the Laravel code but I suppose stranger things have happened.
If I send the POST with the name filled in I do get a proper 201 response back and the record is created on both on the dev and the test system.
I'm guessing it's an issue with Apache or PHP configuration on the Test server but I'm not seeing anything different as far as I can tell. The only other difference is I'm using php-fpm on the test server as I have an app that is still on PHP 7.4 at the moment As one is Windows and the other Linux, it's not straight forward to check the differences.
apache site conf has
<Directory /var/www/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Anyone run in to something like this? Am I missing something on the test server?