Exemple #1
0
 public function actionCreate(Requests\CreatePhotoRequest $request)
 {
     // Create a new model instance and populate it with the request.
     $photo = new Photo($request->all());
     // Check to see if image exists and is valid
     // Redirect with flash message if not.
     if (!$request->hasFile('image')) {
         \Session::flash('flash_message', 'No file selected.');
         return redirect('/photos');
     }
     if (!$request->file('image')->isValid()) {
         \Session::flash('flash_message', 'File is not valid.');
         return redirect('/photos');
     }
     // Set destination path.
     $destinationPath = 'uploads';
     // Set extension.
     $extension = $request->file('image')->getClientOriginalExtension();
     // Set file name.
     $fileName = Uuid::generate(4) . '.' . $extension;
     // Move file to destination path.
     $request->file('image')->move($destinationPath, $fileName);
     // Set file name as photo's image.
     $photo->image = $fileName;
     // Save photo.
     Auth::user()->photos()->save($photo);
     // Attach tags to photo.
     $tags = $request->input('tags');
     if (!is_array($tags)) {
         $tags = [];
     }
     $tagSync = $this->checkTags($tags);
     $photo->tags()->sync($tagSync);
     // Redirect with flash message.
     \Session::flash('flash_message', 'You have successfully created a photo.');
     return redirect('photos');
 }
 public function create(CreatePhotoRequest $request)
 {
     Photo::create($request->all());
     $request->file('photo')->move('photos/' . $request->album_name . '/', $request->photo_name . '.jpg');
     return redirect('pixelbug/loggedin/add');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id, CreatePhotoRequest $request, Photo $photo)
 {
     $photo_to_update = $photo->find($id);
     $uploaded_image = $request->file('image_upload');
     $parameter = $request->all();
     if (isset($uploaded_image)) {
         $ext = $uploaded_image->getClientOriginalExtension();
         $newImageName = $photo_to_update->id . "." . $ext;
         $uploaded_image->move(base_path() . '/public/uploads/images/', $newImageName);
         Image::make(base_path() . '/public/uploads/images/' . $newImageName, array('width' => 774, 'height' => 329))->save(base_path() . '/public/uploads/thumbnails/' . $newImageName);
         $parameter = $request->all();
         $parameter['image'] = $newImageName;
         /* remove this field from the parameters list */
         unset($parameter['image_upload']);
         $photo_to_update->update($parameter);
     } else {
         $photo_to_update->update($request->all());
         $photo_to_update->update($parameter);
     }
     return redirect('photos');
 }