mohiqssh/groups

Laravel 8 用户组包

维护者

详细信息

github.com/mohissh/groups

源代码

v1.4.5 2022-03-03 17:11 UTC

README

Build Status Downloads Packagist StyleCI

目录

  • 描述
  • 安装
    • 使用 Composer 安装
    • 将服务提供者添加到 App
    • 将外观别名添加到 App
    • 使用 Artisan 发布供应商
    • 表详情
    • 使用 Artisan 制作迁移
  • 用法
    • 用户组
      • 创建、删除、更新、用户列表、添加成员、加入请求、接受加入、拒绝加入、加入请求列表
    • 帖子
      • 创建、获取、更新、删除、添加到组、组帖子列表、用户帖子列表
    • 评论
      • 添加、获取、更新、删除
    • 报告
      • 报告、删除、切换、计数
    • 喜欢
      • 喜欢、取消喜欢、切换、计数

描述

此包允许您将用户组 (组、评论、喜欢 ...) 系统添加到您的 Laravel 8 应用程序中。

安装

  1. 通过 Composer,从命令行运行
composer require mohiqssh/groups
  1. 将服务提供者添加到 ./config/app.php 中的 providers 数组,例如
    /*
     * Package Service Providers...
     */
    Mohiqssh\Groups\GroupsServiceProvider::class,
  1. 您可以使用外观来缩短代码。将其添加到 ./config/app.php 中的 aliases 数组末尾
    'Groups' => Mohiqssh\Groups\Facades\GroupsFacade::class,

注意:类绑定到 ioC 为 Groups。

$groups = App::make('Groups');
  1. 从命令行发布资产
php artisan vendor:publish

注意:这将发布在 ./database/migrations/ 中的数据库迁移。

create_groups_table // main groups table
    id
    name
    description
    short_description
    image
    url
    user_id
    private
    conversation_id
    extra_info
    settings

# Usage

## Groups 

1. ##### Create a group

```php
$group = Groups::create($userId, $data);

注意:$data 数组中接受的字段

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

帖子

  1. 创建一个帖子
$post = Groups::createPost($data);

注意:帖子 $data 数组中可接受的有效值

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

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

$posts = $group->posts()->orderBy('id', 'DESC')->paginate(5);
  1. 用户帖子
$user = Groups::getUser($userId);

$posts = $user->posts;

评论

注意:评论 $data 数组中可接受的有效值

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

报告

  1. 报告评论或帖子
$comment->report($userIdOfReporter);
$post->report($userIdOfReporter);
  1. 删除帖子或评论报告
$post->removeReport($userId);
$comment->removeReport($userId);
  1. 切换报告/不报告帖子或评论
$post->toggleReport($userId);
$comment->toggleReport($userId);
  1. 帖子或评论报告计数
$commentReports = $comment->reportsCount;
$postReports = $post->reportsCount;

喜欢

  1. 喜欢帖子或评论
$post->like($userId);
$comment->like($userId);
  1. 不喜欢帖子或评论
$post->unlike($userId);
$comment->unlike($userId);
  1. 切换喜欢/不喜欢帖子或评论
$post->toggleLike($userId);
$comment->toggleLike($userId);
  1. 帖子或评论喜欢计数
$postLikes = $post->likesCount;
$commentLikes = $comment->likesCount;