public function show(Blog $blog, $str) { $comments = $blog->comments()->paginate(config('app.paginat_max')); if ($blog != NULL) { return view('user.blog', compact('blog', 'comments')); } else { return view('errors.404'); } }
public function createComment(Blog $blog, 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 = $blog->id; if ($blog->comments()->save($comment)) { return back()->with('success', trans('validation.comment_success')); } else { return back()->withInput()->with('fail', trans('validation.error')); } }