/** * Store a newly created resource in storage. * * @return Response */ public function storeComment(Comments $comment, CreateCommentRequest $request) { /*$this->validate($request, [ 'nama' => 'required', 'email' => 'required|email', 'komentar' => 'required' ]);*/ $news_slug = News::where('id', $request->input('news_id'))->first()->slug; $comment->create($request->all()); return redirect()->route('news_path', [$news_slug, '#comments-box']); }
public function actionCreate(Requests\CreateCommentRequest $request) { // Create a new model instance and populate it with the request. $comment = new Comment($request->all()); // Find in the database the photo sent with the request. $photo = Photo::findOrFail($request->input('photo_id')); // Attach the comment to the photo. $comment = $photo->comments()->save($comment); // Save the comment in the database. Auth::user()->comments()->save($comment); // Redirect with flash message. \Session::flash('flash_message', 'You have successfully commented on a photo.'); return json_encode($comment); }
public function store(CreateCommentRequest $request, $post_id) { $comment = new Comment(); $post = Post::find($post_id); if ($post && $post->post_author_id != Auth::user()->id) { // store the fields of the comment model $comment->body = $request->input('body'); $comment->comment_author_id = Auth::user()->id; $comment->post_id = $post_id; $comment->created_at = Carbon::now(); $comment->save(); $profile_image_name = Profile::whereUserId(Auth::id())->pluck('profile_image_name'); return response()->json(array('body' => $comment->body, 'comment_author_id' => $comment->comment_author_id, 'post_id' => $comment->post_id, 'comment_id' => $comment->id, 'profile_image_name' => $profile_image_name, 'nickname' => $request->user()->nickname, 'user_id' => Auth::id(), 'message' => 'Comment Saved Successfully', 'status' => 'success')); } return response()->json(array('message' => 'Unauthorized Attempt to create comment', 'status' => 'failed')); }