Attach a comment to this model as a specific user.

@param Model|null $user
@param string $comment
@return \Illuminate\Database\Eloquent\Model
771752
public function commentAsUser(?Model $user, string $comment)
    {
        $commentClass = config('comments.comment_class');

        $comment = new $commentClass([
            'comment' => $comment,
            'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
            'user_id' => is_null($user) ? null : $user->getKey(),
            'commentable_id' => $this->getKey(),
            'commentable_type' => get_class(),
        ]);

        return $this->comments()->save($comment);
    }
106301
public function add($comment)
    {
        if (is_array($comment)) {
            $this->collection[] = new Comment($comment);
        } elseif (is_object($comment) && $comment instanceof Comment) {
            $this->collection[] = $comment;
        }

        return $this;
    }
1169836
public function setComment(\Innova\CollecticielBundle\Entity\Comment $comment)
    {
        $this->comment = $comment;

        return $this;
    }
543351
public function create(Comment &$comment)
    {
        $data = $comment->exportData();
        $endpoint = '/admin/comments.json';
        $respoinse = $this->request(
            $endpoint, 'POST', array(
            'comment' => $data
            )
        );
        $comment->setData($response['comment']);
    }
117007
public function update(Request $request, Comment $comment)
    {
        $attributes = $request->validate([
            'text' => 'required'
        ]);

        tap($comment)
            ->update($attributes)
            ->clearMentions()
            ->mention($request->mentions);

        return back();
    }
794426
public static function add_comment($commenttext, $width, $colour) {
        global $DB, $USER;

        $comment = new \stdClass();
        $comment->userid = $USER->id;
        $comment->rawtext = $commenttext;
        $comment->width = $width;
        $comment->colour = $colour;

        $comment->id = $DB->insert_record('assignfeedback_editpdf_quick', $comment);
        return $comment;
    }
38519
public static function create($comment) {
    $block_comment = new LineCommentBlockNode();
    $comment = trim($comment);
    $lines = array_map('rtrim', explode("\n", $comment));
    foreach ($lines as $line) {
      $comment_node = new CommentNode(T_COMMENT, '// ' . $line . "\n");
      $block_comment->addChild($comment_node);
    }
    return $block_comment;
  }
1075271
public function addCommentToHistory(EntityInterface $entity, string $comment, string $userId = null): ModelHistory
    {
        if (!$userId) {
            $userId = $this->_getUserId();
        }

        return $this->ModelHistory->addComment($entity, $comment, $userId);
    }
130121
public function attachUser( $user )
  {
    if( is_object($user))
      $user = $user->getKey();

    if( is_array($user))
      $user = $user['id'];

    $this->users()->attach( $user );
  }
1074008
public function findByUserWithWidgetsAndComments(User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->select('p')
            ->leftJoin('p.comments', 'comments')
            ->andWhere('p.user = :userId')
            ->setParameter('userId', $user->getId())
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
886630
public function dispatchCommentOnAddEvent(CommentInterface $comment)
    {
        $event = new CommentOnAddEvent(
            $comment
        );

        $this
            ->eventDispatcher
            ->dispatch(ElcodiCommentEvents::COMMENT_ONADD, $event);

        return $this;
    }
1046903
public function addComment($comment)
    {
        if (is_string($comment)) {
            $comment = Placeholder::replaceCommentPlaceholders($comment, true);

            $this->comments[] = $comment;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($comment). "' for argument 'comment' given."
            );
        }

        return $this;
    }
1022459
public function addComment(ResourceComment $comment)
    {
        if (!$this->comments->contains($comment)) {
            $this->comments->add($comment);
        }
    }
819807
protected function setCreatedBy(Model $model, $user)
    {
        $model->{$this->getColumn($model, 'created')} = $user->id;

        if ($model instanceof CreatorAware) {
            $model->setRelation('creator', $user);
        }

        return $model;
    }
248863
private function updateComment($id=NULL)
	{
		$model = $this->getCommentModel($id);

		// Make sure the user has permission to edit this comment
		if ($this->user->user_role != 6 && $this->user->user_role != 9)
		{
			if ($model->user_id != $this->user->id)
				throw new CHttpException(403, Yii::t('Api.comment', 'You do not have permission to edit this comment'));
		}

		$model->attributes = $_POST;
		$model->user_id = $this->user->id;

		if ($model->save())
			return $model->getApiAttributes();

		return $this->returnError(400, NULL, $model->getErrors());
	}
249515
public function reply(Request $request, Comment $comment)
    {
        $this->authorize('reply-to-comment', $comment);

        $this->validate($request, [
            'message' => 'required|string'
        ]);

        $reply = new Comment;
        $reply->commenter()->associate(auth()->user());
        $reply->commentable()->associate($comment->commentable);
        $reply->parent()->associate($comment);
        $reply->comment = $request->message;
        $reply->save();

        return redirect()->to(url()->previous() . '#comment-' . $reply->id);
    }
1142365
public function addComment(Model $model, string $comment) : Comment
    {
        return $model->comments()->create([
            'user_id' => $this->id,
            'comment' => $comment,
        ]);
    }