我使用多态性(一对多)来保存产品的照片并将产品保存在ProductController中:
public function store(ProductRequest $request)
{
$product=product::create($request->all());
$id=$product->id;
foreach ($request->photos as $photo) {
$year = Carbon::now()->year;
$month = Carbon::now()->month;
$day = Carbon::now()->day;
$imagePath = "/upload/images/{$year}/{$month}/{$day}";
$path = $photo->store( $imagePath, 'public');
$product->photos()->create(['path'=>$path,'imageble_id'=>$id, 'imagable_type' => Product::class]);
}
$request->session()->flash('success', 'محصول با موفقیت ثبت شد!');
return redirect(route('Products.index'));
}
如何在刀片中显示与产品相关的所有照片?