public function update(CreateCommentRequest $request, $id) { $comment = $this->comment; $comment->user_id = $request->get('name'); $comment->content = $request->get('content'); $comment->project_id = $id; $comment->save(); $project = Project::whereId($id)->first(); $slug = $project->slug; $task = new Task(); $tasks = $task->whereProject_id($id)->orderBy('id', 'desc')->first(); //return view('projects.show', ['project' => $project, 'task' => $tasks]); return redirect()->route('projects.show', ['slug' => $slug, 'task' => $tasks]); }
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')); } }