从数据库中删除一个数据数组

时间:2017-07-10 09:34:49

标签: php database laravel-5.3

我想删除一个Data Photo产品,但我不能。

产品图片:

enter image description here

我的数据库产品:

enter image description here

这是我的控制器



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;
&#13;
&#13;

0 个答案:

没有答案