/** * 从 Reply 对象初始化通知信息. * * @param Reply $reply * @param $from_user_id * @param null $user_id */ public function setNotificationInfoFromReply(Reply $reply, $from_user_id, $user_id = null) { $this->body = $reply->body; $this->topic_id = $reply->topic_id; $this->reply_id = $reply->id; $this->user_id = $user_id ?: $reply->topic()->pluck('user_id'); $this->from_user_id = $from_user_id; if (isset($this->notification_type)) { $this->type = $this->type ?: $this->notification_type; } }
public function create(array $attributes) { if (!is_null($this->validator)) { $this->validator->with($attributes)->passesOrFail(ValidatorInterface::RULE_CREATE); } $reply = new Reply($attributes); $reply->user_id = Auth::id(); $reply->body = app('markdown')->text($attributes['body']); $reply->body_original = $attributes['body']; $reply->save(); return $reply; }
/** * 发布新的评论. * * @param array $attributes * * @return Reply */ public function store(array $attributes) { if (!is_null($this->validator)) { $this->validator->with($attributes)->passesOrFail(ValidatorInterface::RULE_CREATE); } $reply = new Reply($attributes); $reply->user_id = Auth::id(); $reply->body = app('markdown')->text($attributes['body']); $reply->body_original = $attributes['body']; $reply->save(); $reply->topic()->getQuery()->increment('reply_count'); event(new NewReply($reply, Auth::id(), $reply->topic()->getQuery()->pluck('user_id'))); return $reply; }