Reputation: 77
I want to delete record Photo and Photo_list from Database but give me error
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'));
}
Upvotes: 0
Views: 2023
Reputation: 1405
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'));
}
Upvotes: 0
Reputation: 558
I don't think you can delete specific data with delete. Delete is used to remove a row.
You will need to update your table with a request like that :
public function deletephoto($id)
{
$product = $this->productRepository->findWithoutFail($id);
Product::where('id', 100)->update(['photo' => NULL, 'photo_list' => NULL]);
return redirect(route('stores.index'));
}
You can see more here :
https://laravel.com/docs/5.3/eloquent#updates
https://laravel.com/docs/5.3/eloquent#deleting-models
Upvotes: 1
Reputation: 15941
public function deletephoto($id)
{
$product = $this->productRepository->findWithoutFail($id);
Product::Where('id','=',$product->id)->delete();
return redirect(route('stores.index'));
}
Or you can directly do this
Product::find($id)->delete();
Upvotes: 0