I'm writing a test case to simulate a creation of a product. When creating the product, I'm passing an array of formats, and for some reasons, when validating with the controller, the thumbnail
key is missing from the data.
This is the data I'm sending:
"formats" => array:1 [
0 => array:3 [
"upc" => "584979099857"
"vcode" => "VX43V14FN910479274209"
"thumbnail" => null
]
]
And I send it like the following in my test case:
$response = $this->post(route('products.store'), $product);
For some reasons, when sending the request, the thumbnail => null
disappears from the formats attribute.
Therefore, when validating the request, I always get the error that the thumbnail has to be present.
request()->validate([
'formats' => 'bail|required|array',
'formats.*.upc' => 'bail|required|string|max:255',
'formats.*.vcode' => 'bail|required|string|max:255',
'formats.*.thumbnail' => 'bail|present|image'
]);
I've also tried changing the rules of thumbnail to:
bail|required|nullable|image
Or
bail|nullable|required|image
But then I get the required error.
Does anyone know why the thumbnail
key is getting removed from the formats
array upon sending the request?