I have two tables which are related one is product table and products_photos table. In products_photos table there is "id","product_id" and "filename" columns.I'm trying to edit multiple images when editing a product, the problem is I'm getting an error Method Illuminate\Http\Request::photos does not exist.
. How can I edit multiple images?
Code.
This is how I create multiple images
public function store(Request $request)
{
foreach ($request->photos as $photo) {
$filename = $photo->store('public/photos');
ProductsPhoto::create([
'product_id' => $product->id,
'filename' => $filename
]);
}
return redirect()->back();
}
This is how I edit multiple images
$image = Product::with('ProductsPhoto')->where('id',$request->product_id)->first();
if($request->photos('photos')) {
if(file_exists($image ->photos)){
unlink($image ->photos);
}
$filename = $photos->store('public/photos');
ProductsPhoto::create([
'product_id' => $product->id,
'filename' => $filename
]);
}
else{
$image = $photos->store('public/photos');
}
$product = Product::with('ProductsPhoto')->find($request->product_id);
$product->filename = $product->ProductsPhoto[0]->filename;
$product->save();
}
Blade
<input multiple="multiple" name="photos[]" type="file">
Your help would be appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire