app/Http/Controllers/CommentsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
      $this->validate($request, [
        'body' => 'required'
      ]);
      $comment = new Comment;
      $comment->body = $request->get('comment_body');
      $comment->user()->associate($request->user());
      $post = Post::find($request->get('post_id'));
      $post->comments()->save($comment);
      return 'Done';
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'body' => 'required' ] ) ; $ comment = new Comment ; $ comment -> body = $ request -> get ( 'comment_body' ) ; $ comment -> user ( ) -> associate ( $ request -> user ( ) ) ; $ post = Post :: find ( $ request -> get ( 'post_id' ) ) ; $ post -> comments ( ) -> save ( $ comment ) ; return 'Done' ; }
Store a newly created resource in storage.
Store a newly created resource in storage .