/** * Action: Delete resource images * @return Response */ public function deleteUpload($id) { // Only allows you to share pictures on the cover of the current resource being deleted $filename = TravelPictures::where('id', $id)->where('user_id', Auth::user()->id)->first(); $oldImage = $filename->filename; $model = $this->model->find($filename->travel_id); $oldThumbnails = $model->thumbnails; if (is_null($filename)) { return Redirect::back()->with('error', '没有找到对应的图片'); } elseif ($filename->delete()) { destoryUploadImages($this->destinationPath, $oldImage); if ($oldImage == $oldThumbnails) { $model->thumbnails = NULL; $model->save(); destoryUploadImages($this->largeThumbnailsPath, $oldThumbnails); destoryUploadImages($this->smallThumbnailsPath, $oldThumbnails); } return Redirect::back()->with('success', '图片删除成功。'); } else { return Redirect::back()->with('warning', '图片删除失败。'); } }
/** * Action: Delete resource images * @return Response */ public function deleteUpload($id) { // Only allows you to share pictures on the cover of the current resource being deleted $filename = TravelPictures::where('id', $id)->where('user_id', Auth::user()->id)->first(); $oldImage = $filename->filename; if (is_null($filename)) { return Redirect::back()->with('error', '没有找到对应的图片'); } elseif ($filename->delete()) { File::delete(public_path('uploads/travel/' . $oldImage)); return Redirect::back()->with('success', '图片删除成功。'); } else { return Redirect::back()->with('warning', '图片删除失败。'); } }