5
Well I have a product and I have an image being recorded locally.
I need that in the backend when the product is deleted the local image is deleted.
When I delete deletes the database data deletes the image information in the database, but does not delete the local image.
What’s the best way to do it?
My route :
Route::get('/{id}/destroy',['as'=>'products.destroy', 'uses'=>'AdminProductsController@destroy']);
My function to delete the product:
public function destroy($id)
{
$this->productModel->find($id)->delete();
return redirect()->route('products');
}
Function to remove image in image view
public function destroyImage(ProductImage $productImage, $id)
{
$image = $productImage->find($id);
if(file_exists(public_path() .'/uploads/'.$image->id.'.'.$image->extension)) {
Storage::disk('public_local')->delete($image->id . '.' . $image->extension);
}
$product = $image->product;
$image->delete();
return redirect()->route('products.images', ['id'=>$product->id]);
}
The local image would be on the machine in the customer?
– gmsantos
On the local server
– raphael