public function postEditComment(CreateCommentRequest $request, $id)
 {
     try {
         $comment = Comment::findOrFail($id);
         // asume the use always has a profile.
         $profile_image_name = Profile::whereUserId($request->user()->id)->pluck('profile_image_name');
         if ($comment && $comment->comment_author_id == Auth::user()->id) {
             $comment->body = $request->get('body');
             $comment->updated_at = Carbon::now();
             $comment->save();
             return response()->json(array('message' => 'Your Comment has been updated', 'status' => 'success', 'body' => $comment->body, 'user_id' => Auth::id(), 'profile_image_name' => $profile_image_name, 'comment_id' => $comment->id, 'nickname' => $request->user()->nickname, 'comment_author_id' => $comment->comment_author_id));
         }
     } catch (ModelNotFoundException $e) {
         return response()->json(array('message' => 'Unauthorized attempt to update comment', 'status' => 'failed'));
     }
 }
 public function postEdit(Request $request, $id)
 {
     //try some validation.
     $rules = ['title' => 'required|min:3', 'body' => 'required'];
     // validate the submitted post for editing
     $this->validate($request, $rules);
     $post = Post::find($id);
     // if the post exist and is written by this user.
     if ($post && $post->post_author_id == Auth::user()->id) {
         $post->title = Input::get('title');
         $post->body = Input::get('body');
         $post->save();
         $profile_image_name = Profile::whereUserId(Auth::id())->pluck('profile_image_name');
         return response()->json(array('message' => 'Post edited', 'status' => 'success', 'title' => $post->title, 'body' => $post->body, 'profile_image_name' => $profile_image_name, 'post_id' => $post->id, 'nickname' => $request->user()->nickname, 'post_author_id' => $post->post_author_id, 'user_id' => Auth::id()));
     }
     return response()->json(array('message' => 'You do not have permission to edit this post', 'status' => 'Unauthorized attempt'));
 }
 /**
  * Update the user's profile in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request)
 {
     $profile = Profile::whereUserId(Auth::id())->firstOrFail();
     $profile->update($request->all());
     return redirect('/');
 }
Esempio n. 4
0
 public static function getUserProfileImageNameByPost($post_author_id)
 {
     $profile = Profile::whereUserId($post_author_id)->get()->first();
     return $profile->profile_image_name;
 }
 public static function getUserProfileImageNameByCommentReply($comment_reply_author_id)
 {
     try {
         $profile = Profile::whereUserId($comment_reply_author_id)->firstOrFail();
         return $profile->profile_image_name;
     } catch (ModelNotFoundException $e) {
         return UserController::getDefaultImageName();
     }
 }
 public static function getUserProfileImageName($author_id)
 {
     $profile = Profile::whereUserId($author_id)->get()->first();
     return is_null($profile) ? null : $profile->profile_image_name;
 }