Search code examples
phplaravel-5.3

Laravel - Delete data record from Database


I want to delete record Photo and Photo_list from Database but give me error

This is my database Product

This is my Code in Controller

public function deletephoto($id)
{

    $product = $this->productRepository->findWithoutFail($id);
    Product::select('photo','photo_list')->delete($product->id);

    return redirect(route('stores.index'));

}

Solution

  • You can try this :

    public function deletephoto($id)
        {
    
            $product = $this->productRepository->findWithoutFail($id);
            if($product){
              $product->photo= null;
              $product->photo_list= null;
              $product->save();
            }
    
            return redirect(route('stores.index'));
    
        }