Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, UpdateArticleRequest $request)
 {
     $request = $this->imageHandler->handleRequest($request);
     $article = Article::find($id);
     $article->update($request->all());
     $article->tags()->sync($request->get("tags"));
     return redirect()->route("dashboard.articles.index");
     // see php artisan route:list
 }
 /**
  * Saves the user profile picture
  *
  * @return string
  */
 public function postSaveUserProfilePicture()
 {
     try {
         //User must be logged in
         if (!$this->auth->check()) {
             //Raise error
             throw new Exception('You must login', 401);
         }
         //Generate filename
         $filename = Uuid::uuid4()->toString();
         //Resize to 100x100
         $image = $this->imageHandler->resizeImage($this->imageHandler->makeImage($_FILES['profile_picture']['tmp_name'])->encode('png'), 200, 200);
         //Save the image
         $results = $this->imageHandler->saveImage($image, public_path('img/profile-pictures'), $filename . '.png');
         //Could not save image
         if ($results == false) {
             //Raise error
             throw new Exception('Unable to save image', 422);
         }
         //Delete old picture
         if ($this->auth->user()->hasProfilePic()) {
             //Delete the old profile picture
             $this->filesystem->delete('public/img/profile-pictures/' . $this->auth->user()->detail->getOriginal('profile_picture') . '.png');
         }
         //Save the new profile picture of the user
         $saved = $this->userRepo->saveUserDetails($this->auth->user(), ['profile_picture' => $filename]);
         //Could not save picture
         if ($saved == null) {
             //Raise error
             throw new Exception('Could not save image', 422);
         }
         //Go back to previous page
         redirect($this->agent->referrer(), 'location');
     } catch (Exception $e) {
         //Unexpected error
         show_error($e->getMessage(), 500);
     }
 }