điều khiển chức năng:Cách lấy hình ảnh đơn lẻ từ một mảng Hình ảnh được chèn vào trong laravel?
<?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);
}
?>
Đây là chức năng lưu trữ của tôi để lưu trữ mảng của hình ảnh.
Function Để lấy hình ảnh duy nhất từ một loạt các hình ảnh:
<?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();
?>
Ở đây tôi chọn imagefile từ table.It fetches nhiều hình ảnh được lưu trữ dựa trên id.But duy nhất tôi chỉ cần một hình ảnh từ mảng hình ảnh được lưu trữ.
giới hạn sử dụng trong truy vấn để có được hình ảnh đơn – pravindot17
bạn vui lòng chỉ định rõ ràng –
Tôi đề nghị sử dụng '-> groupBy ('productPriceDetails.productId')' làm giải pháp. nhưng vấn đề chính là trong thiết kế cơ sở dữ liệu của bạn –