Controller function:
<?php
public function addImages(Request $request, $imagesProductId) {
$product = Product::create($request->all());
$filenames = array();
if (empty($request->images)) {
$message = "error";
return Redirect::back()->with('message', $message);
}
$rules = [
'images' => 'mimes:jpeg,jpg,png' // allowed MIMEs
// size in pixels
];
$validator = Validator::make($request->all(), $rules);
$result = $validator->fails() ? 'QCVerified' : 'QCFailed';
foreach ($request->images as $photo) {
// echo($result);
$filename = $photo->store('public/uploadedImages');
$filename = substr($filename, 22);
$filenames[] = asset('storage/uploadedImages/' . $filename);
ProductsPhoto::create([
'nonliveStatus' => $result,
'product_id' => $product->id,
'productId' => $imagesProductId,
'filename' => $filename
]);
}
return response()->json($filenames);
}
?>
This is my storage function for storing array of images.
Function To fetch single image from an array of images:
<?php
$liveValues = priceInfo::join('productDescription', 'productDescription.productId', '=', 'productPriceDetails.productId')
->join('productAdditionalInformation', 'productAdditionalInformation.productId', '=', 'productPriceDetails.productId')
->join('products_photos', 'products_photos.productId', '=', 'productAdditionalInformation.productId')
->select('products_phots.filename')
->where('productPriceDetails.nonliveStatus', '=', "QCVerified")
->get();
?>
Here I am selecting the imagefile from the table.It fetches the multiple images stored based on single id.But I need only one images from the array of images stored.