//These Images
for($i = 0 ; $i < count($request['images']); $i++)
{
$response = $response->attach('images['.$i.']', file_get_contents($request['images'][$i]), 'image.png' );
}
$response = $response->post('...WEB_URL_HIDDEN.../api/merchant/createDeal', [
'name' => 'name',
'discount' => $request->discount,
'type' => $request->type,
'category' => $request->category,
'actual_price' => $request->actual_price,
'price' => $request->price,
'after_discount' => $request->after_discount,
'expiry' => $request->expiry,
'description' => $request->description,
// //These Arrays
'branches' => $request['branches'],
'tags' => $request['tags'],
]);
dd($response->json());
This is my Code for sending Some images and Some Data to an external API. I am sending images in attach() function and sending arrays down there called 'branches' and 'tags'. Now the problem is this that When I submit an error comes as " A 'contents' key is required ". If I comment out attach() then it works well but images do not uploaded. And If a comment out 'branches' and 'tags' arrays then everything works find but arrays do not send to API. In a nutshell, the problem is the trade off between images and arrays.