app/Api/V1/Controllers/CommentController.php
/**
     * create a comment
     *
     * @param Request $request
     * @return Comment
     * @throws \Illuminate\Validation\ValidationException
     */
create a comment
@param Request $request
@return Comment
@throws \Illuminate\Validation\ValidationException
create a comment @param Request $request @return Comment @throws \ Illuminate \ Validation \ ValidationException
public function store(Request $request)
    {
        $rules = [
            'comment' => 'required',
            'model_id' => 'required',
        ];
        $this->validate($request, $rules);
        if (! $surveyReport = SurveyReport::find($request->model_id)) {
            throw new StoreResourceFailedException('survey report not found');
        }
        $comment = new Comment();
        $comment->body = $request->comment;
        $comment->created_by = auth()->id();
        if ($surveyReport->comments()->save($comment)) {
            return $comment;
        }
        throw new StoreResourceFailedException('couldn\'t save comment');
    }
public function store ( Request $ request ) { $ rules = [ 'comment' => 'required' , 'model_id' => 'required' , ] ; $ this -> validate ( $ request , $ rules ) ; if ( ! $ surveyReport = SurveyReport :: find ( $ request -> model_id ) ) { throw new StoreResourceFailedException ( 'survey report not found' ) ; } $ comment = new Comment ( ) ; $ comment -> body = $ request -> comment ; $ comment -> created_by = auth ( ) -> id ( ) ; if ( $ surveyReport -> comments ( ) -> save ( $ comment ) ) { return $ comment ; } throw new StoreResourceFailedException ( 'couldn\'t save comment' ) ; }
create a comment
 @param Request $request
 @return Comment
 @throws \Illuminate\Validation\ValidationException
create a comment @param Request $request @return Comment @throws \ Illuminate \ Validation \ ValidationException
//'model' => 'string'