mohiqssh / groups
v1.4.5
2022-03-03 17:11 UTC
Requires
- laravel/framework: ^8.0
Requires (Dev)
- laravel/legacy-factories: 1.x-dev
- mockery/mockery: ^1.4.4
- orchestra/database: ^6.24.0
- orchestra/testbench: ^6.24.0
- phpunit/phpunit: ^9.5.0
This package is auto-updated.
Last update: 2024-09-29 05:57:04 UTC
README
目录
描述
此包允许您将用户组 (组、评论、喜欢 ...) 系统添加到您的 Laravel 8 应用程序中。
安装
- 通过 Composer,从命令行运行
composer require mohiqssh/groups
- 将服务提供者添加到
./config/app.php
中的providers
数组,例如
/* * Package Service Providers... */ Mohiqssh\Groups\GroupsServiceProvider::class,
- 您可以使用外观来缩短代码。将其添加到
./config/app.php
中的aliases
数组末尾
'Groups' => Mohiqssh\Groups\Facades\GroupsFacade::class,
注意:类绑定到 ioC 为 Groups。
$groups = App::make('Groups');
- 从命令行发布资产
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 ];
$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);
注意:帖子 $data 数组中可接受的有效值
$data = [ 'title' => '', 'user_id' => 0, '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;
评论
注意:评论 $data 数组中可接受的有效值
$data = [ 'post_id' => 0, 'user_id' => 0, 'body' => '', ];
$comment = Groups::addComment($data);
$comment = Groups::comment($commentId);
$comment->update($data);
$comment->delete();
报告
$comment->report($userIdOfReporter); $post->report($userIdOfReporter);
$post->removeReport($userId); $comment->removeReport($userId);
$post->toggleReport($userId); $comment->toggleReport($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;