lifeids/groups

Laravel 5 用户组包

dev-master / 1.0.x-dev 2017-11-17 08:47 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:08:03 UTC


README

此包允许您将用户组系统添加到您的 Laravel 5 应用程序中

安装

在命令行中运行

composer require lifeids/groups

将服务提供者添加到您的 config\app.php 的 providers 数组

Lifeids\Groups\GroupsServiceProvider

您可以使用外观来缩短代码。将其添加到您的别名中

'Groups' => Lifeids\Groups\Facades\GroupsFacade::class` to your `config\app.php

该类绑定到 ioC 为 Groups

$groups = App::make('Groups');

发布资产

php artisan vendor:publish

这将发布数据库迁移。

用户组

创建一个组
$group = Groups::create($userId, $data);

在 $data 数组中接受的字段

$data = [
        'name',
        'description', // optional
        'short_description', // optional
        'image',   // optional
        'private', // 0 or 1
        'extra_info', // optional
        'settings', // optional
        'conversation_id', // optional if you want to add messaging to your groups this can be useful
    ];
删除一个组
$group->delete();
更新一个组
$group->update($updateArray);
获取具有用户关系的用户实例
$user = Groups::getUser($userId); 
将成员添加到组
$group->addMembers([$userId, $userId2, ...]);
加入组的请求
$group->request($userId);
接受组请求
$group->acceptRequest($userId);
拒绝组请求
$group->declineRequest($userId);
组请求
$requests = $group->requests;
用户是组成员的数量
$user = Groups::getUser($userId); 
$count = $user->groups->count();
从组中删除成员
$group->leave([$userId, $userId2, ...]);

帖子

创建帖子
$post = Groups::createPost($data);

Post $data 数组可接受的值

$data = ['title', 'user_id', 'body', 'type', 'extra_info'];
获取帖子
$post = Groups::post($postId);
更新帖子
$post->update($data);
删除帖子
$post->delete();
将帖子添加到组
$group->attachPost($postId);
将多个帖子添加到组
$group->attachPost([$postId, $postId2, ...]);
从组中删除帖子
$group->detachPost($postId);
组帖子
$posts = $group->posts;

$posts = $group->posts()->paginate(5);

$posts = $group->posts()->orderBy('id', 'DESC')->paginate(5);

用户帖子
$user = Groups::getUser($userId);

$posts = $user->posts;

评论

Comment $data 数组可接受的值

$data = ['post_id', 'user_id', 'body'];
添加评论
$comment = Groups::addComment($data);
获取评论
$comment = Groups::comment($commentId);
更新评论
$comment->update($data);
删除评论
$comment->delete();

报告

滥用报告评论或帖子
$comment->abuseReport($userIdOfReporter);
$post->abuseReport($userIdOfReporter);
删除帖子或评论的滥用报告
$post->removeAbuseReport($userId);
$comment->removeAbuseReport($userId);
切换滥用报告/取消报告帖子或评论
$post->toggleAbuseReport($userId);
$comment->toggleAbuseReport($userId);
帖子或评论报告计数
$commentReports = $comment->reportsCount;
$postReports = $post->reportsCount;

点赞

点赞帖子或评论
$post->like($userId);
$comment->like($userId);
取消点赞帖子或评论
$post->unlike($userId);
$comment->unlike($userId);
切换点赞/取消点赞帖子或评论
$post->toggleLike($userId);
$comment->toggleLike($userId);
帖子或评论点赞计数
$postLikes = $post->likesCount;
$commentLikes = $comment->likesCount;