Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateImageRequest $request)
 {
     if ($request->hasFile('imageFile')) {
         $path = public_path() . '/uploads/images';
         $file = $request->file('imageFile');
         $fileName = time() . '_' . $file->getClientOriginalName();
         $file->move($path, $fileName);
         $image = $fileName;
     }
     $image = Image::create(['project_id' => $request->input('project_id'), 'filename' => $image]);
     if ($image) {
         $filename = pathinfo($image->filename, PATHINFO_FILENAME);
         $fileExt = pathinfo($image->filename, PATHINFO_EXTENSION);
         // Resize image
         $img640 = Resizer::make('uploads/images/' . $image->filename)->widen(640);
         $img1280 = Resizer::make('uploads/images/' . $image->filename)->widen(1280);
         $img1920 = Resizer::make('uploads/images/' . $image->filename)->widen(1920);
         $img2560 = Resizer::make('uploads/images/' . $image->filename)->widen(2560);
         // Save images
         $img640->save('uploads/images/' . $filename . '_640.' . $fileExt);
         $img1280->save('uploads/images/' . $filename . '_1280.' . $fileExt);
         $img1920->save('uploads/images/' . $filename . '_1920.' . $fileExt);
         $img2560->save('uploads/images/' . $filename . '_2560.' . $fileExt);
         flash()->success('Image uploaded successfully!');
     } else {
         flash()->error('Oops! Something went wrong.');
     }
     return redirect(route('backend'));
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \App\Http\Requests\CreateImageRequest  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateImageRequest $request)
 {
     //create new instance of model to save from form
     $marketingImage = new Marketingimage(['image_name' => $request->get('image_name'), 'image_extension' => $request->file('image')->getClientOriginalExtension(), 'mobile_image_name' => $request->get('mobile_image_name'), 'mobile_extension' => $request->file('mobile_image')->getClientOriginalExtension(), 'is_active' => $request->get('is_active'), 'is_featured' => $request->get('is_featured')]);
     //define the image paths
     $destinationFolder = '/img/marketing/';
     $destinationThumbnail = '/img/marketing/thumbnails/';
     $destinationMobile = '/img/marketing/mobile/';
     //assign the image paths to new model, so we can save them to DB
     $marketingImage->image_path = $destinationFolder;
     $marketingImage->mobile_image_path = $destinationMobile;
     // format checkbox values and save model
     $this->formatCheckboxValue($marketingImage);
     $marketingImage->save();
     //parts of the image we will need
     $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);
     // now for 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);
     // Process the uploaded image, add $model->attribute and folder name
     flash()->success('Marketing Image Created!');
     return redirect()->route('marketingimages.show', [$marketingImage]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateImageRequest $request)
 {
     //create new instance of model to save from form
     $marketingImage = new Marketingimage(['image_name' => $request->get('image_name'), 'image_extension' => $request->file('image')->getClientOriginalExtension(), 'is_active' => $request->get('is_active'), 'is_featured' => $request->get('is_featured'), 'image_weight' => $request->get('image_weight')]);
     // format checkbox values and save model
     $this->formatCheckboxValue($marketingImage);
     $marketingImage->save();
     //parts of the image we will need
     $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!', 'Marketing Image Created!');
     return redirect()->route('marketing-image.show', [$marketingImage]);
 }