function delete($id)
 {
     $this->respondTo('html', function () use($id) {
         $response = $this->getResponse();
         $flash = $this->getSession()->getFlashBag();
         $image = Image::find($id);
         $product_id = $image->product->id;
         if ($image == null) {
             $flash->add('errors', "Image #{$id} not found");
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$product_id]);
             return;
         }
         try {
             $image->destroy();
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$product_id]);
         } catch (\Exception $e) {
             $flash->add('errors', $e->getMessage());
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$product_id]);
         }
     });
 }
 public function uploadPicture($id)
 {
     $this->respondTo('html', function () use($id) {
         $response = $this->getResponse();
         $flash = $this->getSession()->getFlashBag();
         $files_bag = $this->getRequest()->getFiles();
         $picfile = $files_bag->get('picture');
         if ($picfile == null) {
             $flash->add('errors', 'no file uploaded');
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$id]);
             return;
         }
         $product = Product::find($id);
         if ($product == null) {
             $flash->add('errors', "Product #{$id} cannot be found");
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'index');
             return;
         }
         Image::saveUploadedImage($product, $picfile);
         $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$id]);
     });
 }