public function removeImage(Request $request, $slug) { if ($request->imageName) { $projectImage = ProjectImage::where('img_thumb', $request->imageName)->firstOrFail(); $projectPath = 'build/images/projects/' . $slug . '/'; $thumbnail = $projectImage->img_thumb; $imgOrigin = $projectImage->img_origin; if ($projectImage->img_thousand != null) { $imgThousand = $projectImage->img_thousand; } // removing images from disk Storage::disk('public')->delete($projectPath . $thumbnail); Storage::disk('public')->delete($projectPath . $imgOrigin); if (isset($imgThousand)) { Storage::disk('public')->delete($projectPath . $imgThousand); } // removing table row from database $projectImage->delete(); return 'ok'; } else { return 'failed'; } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $gallery_image = ProjectImage::findOrFail($id); $gallery_image->delete(); Session::flash('flash_message', 'Image successfully deleted!'); return redirect()->back(); }