Пример #1
0
 /**
  * bind an image to quiz
  * @param $image
  * @param $quiz
  */
 protected function bindImage($image, $quiz)
 {
     $this->uploader->upload($image, config('image.quizzesDESTINATION'))->save(config('image.quizzesDESTINATION'));
     $picture = Picture::create(['path' => $this->uploader->getFilename()]);
     $quiz->picture()->attach($picture);
 }
Пример #2
0
 public function userPhoto(UserPhotoRequest $request)
 {
     $user = User::find($request->user()->id);
     if (\Input::hasFile('photo')) {
         // upload image
         $image = \Input::file('photo');
         $imagesPath = 'images/users';
         $this->uploader->upload($image, $imagesPath)->save($imagesPath);
         if ($user->picture()) {
             $picture = $user->picture()->get();
             foreach ($picture as $pic) {
                 User::deleteImage($pic->path);
             }
             $user->picture()->detach();
         }
         $picture = Picture::create(['path' => $this->uploader->getFilename()]);
         $user->picture()->attach($picture);
     }
     Toastr::info(trans('messages.yourPhotoUpdated'), $title = $user->name, $options = []);
     return redirect()->back();
 }
Пример #3
0
 /**
  * @param $slug
  * @param PostsUpdateFormRequest $request
  * @return Redirect
  */
 public function update($slug, PostsUpdateFormRequest $request)
 {
     try {
         $post = Post::findBySlugOrId($slug);
         $data = $request->all();
         unset($data['image']);
         $data['user_id'] = \Auth::id();
         $data['slug'] = Str::slug($data['title']);
         if (\Input::hasFile('image')) {
             // upload image
             $image = \Input::file('image');
             if ($post->picture()) {
                 $picture = $post->picture()->get();
                 foreach ($picture as $pic) {
                     Post::deleteImage($pic->path);
                 }
                 $post->picture()->detach();
             }
             $post->update($data);
             $post->untag();
             $post->tag($request->input('tags_list'));
             $this->uploader->upload($image, 'images/posts/')->save('images/posts');
             $picture = Picture::create(['path' => $this->uploader->getFilename()]);
             $post->picture()->attach($picture);
         } else {
             $post->update($data);
             $post->untag();
             $post->tag($request->input('tags_list'));
         }
         $updatedPost = $post->id;
         Toastr::success(trans('messages.yourPostUpdated'), $title = $post->title, $options = []);
         return redirect()->to(App::getLocale() . '/blog/post/' . $updatedPost);
     } catch (ModelNotFoundException $e) {
         return $this->redirectNotFound();
     }
 }