本文整理汇总了PHP中app\Course::comments方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::comments方法的具体用法?PHP Course::comments怎么用?PHP Course::comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Course
的用法示例。
在下文中一共展示了Course::comments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: course
/**
* Created By Dara on 8/2/2016
* add reply to comment
*/
public function course(Course $course, $comment_id, Request $request)
{
$user = $this->user;
$this->validate($request, ['content' => 'required']);
if ($comment_id) {
//check if the comment has been set or not (reply) level 2 comment
$comment = Comment::findOrFail($comment_id);
$parent_id = $comment->id;
$msg = trans('users.answerSent');
$nested = true;
} else {
//level 1 comment
$parent_id = 0;
$msg = trans('users.commentSent');
$nested = false;
}
//add comment to db
$newComment = $course->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]);
$numComment = $course->comments()->count();
$course->update(['num_comment' => $numComment]);
$obj = $course;
$model = 'course';
return ['hasCallback' => 1, 'callback' => 'course_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'course', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]];
}