Exemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \App\Http\Requests\EditImageRequest  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id, EditImageRequest $request)
 {
     $marketingImage = Marketingimage::findOrFail($id);
     $marketingImage->is_active = $request->get('is_active');
     $marketingImage->is_featured = $request->get('is_featured');
     $this->formatCheckboxValue($marketingImage);
     $marketingImage->save();
     if (!empty(Input::file('image'))) {
         $destinationFolder = '/img/marketing/';
         $destinationThumbnail = '/img/marketing/thumbnails/';
         $file = Input::file('image');
         $imageName = $marketingImage->image_name;
         $extension = $request->file('image')->getClientOriginalExtension();
         //create instance of image from temp upload
         $image = Image::make($file->getRealPath());
         //save image with thumbnail
         $image->save(public_path() . $destinationFolder . $imageName . '.' . $extension)->resize(60, 60)->save(public_path() . $destinationThumbnail . 'thumb-' . $imageName . '.' . $extension);
     }
     if (!empty(Input::file('mobile_image'))) {
         $destinationMobile = '/img/marketing/mobile/';
         $mobileFile = Input::file('mobile_image');
         $mobileImageName = $marketingImage->mobile_image_name;
         $mobileExtension = $request->file('mobile_image')->getClientOriginalExtension();
         //create instance of image from temp upload
         $mobileImage = Image::make($mobileFile->getRealPath());
         $mobileImage->save(public_path() . $destinationMobile . $mobileImageName . '.' . $mobileExtension);
     }
     flash()->success('image edited!');
     return view('marketingimages.edit', compact('marketingImage'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id, EditImageRequest $request)
 {
     $marketingImage = MarketingImage::findOrFail($id);
     // assign new values to attributes
     $marketingImage->is_active = $request->get('is_active');
     $marketingImage->is_featured = $request->get('is_featured');
     $marketingImage->image_weight = $request->get('image_weight');
     // if file, assign file extension to model attribute
     if (!empty(Input::file('image'))) {
         // delete old images before saving new
         File::delete(public_path($this->destinationFolder) . $marketingImage->image_name . '.' . $marketingImage->image_extension);
         File::delete(public_path($this->destinationThumbnail) . 'thumb-' . $marketingImage->image_name . '.' . $marketingImage->image_extension);
         $marketingImage->image_extension = $request->file('image')->getClientOriginalExtension();
     }
     $this->formatCheckboxValue($marketingImage);
     $marketingImage->save();
     // check for file, if file, overwrite existing file
     if (!empty(Input::file('image'))) {
         $file = Input::file('image');
         $imageName = $marketingImage->image_name;
         $extension = $request->file('image')->getClientOriginalExtension();
         //create instance of image from temp upload
         $image = Image::make($file->getRealPath());
         //save image with thumbnail
         $image->save(public_path() . $this->destinationFolder . $imageName . '.' . $extension)->resize(60, 60)->save(public_path() . $this->destinationThumbnail . 'thumb-' . $imageName . '.' . $extension);
     }
     alert()->success('Congrats!', 'image edited!');
     return view('marketing-image.show', compact('marketingImage'));
 }