First make sure that your form has this
enctype="multipart/form-data
Then try removing this line from your validation
'images.*' => 'mimes:jpg,jpeg,png,bmp,gif,svg,webp,pdf,docx|max:1024',
I also suggest cheking out intervention
I'm trying to create an API to store the value but my image store is not working,
For image upload, I'm using polymorphic table with hasMany relations. But I don't why it is not storing.
plz check my code what i did wrong...?
THis is my api controller
public function store(Request $request)
{
$validatedData = $request->validate([
'product_name' => 'required',
'product_category_id' => 'required|not_in:0',
'sub_category_id' => 'required|not_in:0',
'company_id' => 'required|not_in:0',
'product_quantity' => 'nullable|numeric',
'unit_id' => 'nullable|numeric|not_in:0',
'purchase_price' => 'nullable',
'city' => 'nullable|string|max:255',
// 'isChecked' => 'required|accepted',
'details' => 'required|string|min:5',
'images.*' => 'mimes:jpg,jpeg,png,bmp,gif,svg,webp,pdf,docx|max:1024',
]) + [
'user_id' => auth()->user()->id,
];
// $storedData = auth()->user()->rfqs()->create($validatedData);
$storedData = Rfq::create($validatedData);
if ($request->hasFile('images')) {
foreach ($request->file('images') as $photo) {
dd($photo); // this is also not working
$path_url = $photo->storePublicly('rfqs', 'public');
$storedData->images()->create([
'file_name' => $photo->getClientOriginalName(),
'mime_type' => $photo->getMimeType(),
'file_path' => $path_url,
]);
}
}
$response = new RfqResource($storedData);
return response()->json(['status' => 'success', 'data' => $response]);
}
THis direct show me the output....
Please or to participate in this conversation.