コード例 #1
0
ファイル: SamplesController.php プロジェクト: majid-n/laravel
 public function createComment(Sample $sample, Request $request)
 {
     $input = $request->all();
     $body = $input['body'];
     $rules = ['body' => 'required|min:2'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return back()->withInput()->withErrors($validator);
     }
     $user = Sentinel::getUser()->id;
     $comment = new Comment();
     $comment->body = $body;
     $comment->user_id = $user;
     $comment->commentable_id = $sample->id;
     if ($sample->comments()->save($comment)) {
         return back()->with('success', trans('validation.comment_success'));
     } else {
         return back()->withInput()->with('fail', trans('validation.error'));
     }
 }