本文整理汇总了PHP中app\Comment::isUserLiked方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::isUserLiked方法的具体用法?PHP Comment::isUserLiked怎么用?PHP Comment::isUserLiked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Comment
的用法示例。
在下文中一共展示了Comment::isUserLiked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: likeComment
public function likeComment($payload, Comment $comment)
{
if ($comment->isUserLiked($payload['user_id'])) {
return array('result' => false, 'message' => 'The comment has been liked by this user!');
}
\DB::beginTransaction();
try {
$like = CommentLike::create(['comment_id' => $comment->id, 'user_id' => $payload['user_id']]);
\DB::commit();
return array('result' => true, 'content' => $like);
} catch (\Exception $e) {
\DB::rollBack();
return array('result' => false, 'message' => $e->getMessage());
}
}
示例2: transform
public function transform(Comment $comment)
{
$likes = $comment->likes;
return ['id' => $comment->id, 'user_id' => $comment->user_id, 'moment_id' => $comment->moment_id, 'text' => $comment->text, 'like_count' => $likes->count(), 'is_liked' => $comment->isUserLiked($this->request_user_id), 'created_at' => $comment->created_at->toDateTimeString(), 'updated_at' => $comment->updated_at->toDateTimeString()];
}