Advertisement
Twissel

ImageController@getDelete

Aug 22nd, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. public function getDelete($id) {
  2.         //Let's first find the image
  3.         $image = Photo::find($id);
  4.  
  5.         //If there's an image, we will continue to the deletingprocess
  6.         if($image) {
  7.             //First, let's delete the images from FTP
  8.             File::delete(Config::get('image.upload_folder').'/'$image->image);
  9.     File::delete(Config::get('image.thumb_folder').'/'$image->image);
  10.  
  11.     //Now let's delete the value from database
  12.     $image->delete();
  13.  
  14.     //Let's return to the main page with a success message
  15.     return Redirect::to('/')->with('success','Image deleted successfully');
  16.  
  17.   } else {
  18.             //Image not found, so we will redirect to the indexpage with an error message flash data.
  19.             return Redirect::to('/')->with('error','No image with given ID found');
  20.         }
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement