我想删除一个Data Photo产品,但我不能。
产品图片:
我的数据库产品:
这是我的控制器
public function edit($id)
{
$product = $this->productRepository->findWithoutFail($id);
$store = Store::pluck('name', 'id')->all();
$photo = json_decode($product->photo_list);
$category = Category::pluck('name','id')->all();
if (empty($product)) {
Flash::error('Product not found');
return redirect(route('products.index'));
}
return view('products.edit',compact('product','store','category','photo'));
}

这是我的删除功能
public function deletephoto($id)
{
$product = $this->productRepository->findWithoutFail($id);
$photo = json_decode($product->photo_list);
//dd($photo);
if($photo){
$photo->id= null;
$photo->name= null;
//$this->productRepository->delete($id);
$product->save();
}
Flash::success('Photo deleted successfully.');
return back();
}

这是我的观点blade.php
@foreach($photo as $pro)
<div style="margin-right:10px" class="form-group col-sm-1">
<p><img src="{{ env('FRONTEND_URL') . "/img/products/$product->id/$pro->name"}}" width="100" height="100"/></p>
<a href="{!! route('products.deletephoto', [$pro->id]) !!}" class='btn btn-default btn-xs' onclick="return confirm('Are you sure?')">Delete</a>
</div>
@endforeach
&#13;