musonza/groups
Table of content
- Description
- Installation
- Install with Composer
- Add service provider to App
- Add facade alias to App
- Publish vendor with Artisan
- Tables details
- Make migration with Artisan
- Usage
- Groups
- Create, Delete, Update, Users list, Add member, Join request, Accept join, Decline join, Join request list
- Posts
- Create, Get, Update, Delete, Add to group, Group posts list, User posts list
- Comments
- Add, Get, Update, Delete
- Reporting
- Report, Remove, Toggle , Count
- Likes
- Like, Unlike, Toggle, Count
- Groups
Description
This package allows you to add user groups (groups, comment, like ...) system to your Laravel 5 application.
Installation
- Via Composer, from the command line, run :
composer require musonza/groups
- Add the service provider to
./config/app.phpinprovidersarray, like :
/*
* Package Service Providers...
*/
Musonza\Groups\GroupsServiceProvider::class,
- You can use the facade for shorter code.
Add this to
./config/app.phpat the end ofaliasesarray :
'Groups' => Musonza\Groups\Facades\GroupsFacade::class,
Note : The class is bound to the ioC as Groups.
$groups = App::make('Groups');
- From the command line, publish the assets:
php artisan vendor:publish
Note : This will publish database migrations in
./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);
Note : Accepted fields in $data array :
$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
];
-
Delete a group
$group->delete();
-
Update a group
$group->update($updateArray);
-
Get user instance with group relations
$user = Groups::getUser($userId);
-
Add members to group
$group->addMembers([$userId, $userId2, ...]);
-
Request to join a group
$group->request($userId);
-
Accept a group request
$group->acceptRequest($userId);
-
Decline a group request
$group->declineRequest($userId);
-
Group requests
$requests = $group->requests;
-
How many groups a user is member of
$user = Groups::getUser($userId);
$count = $user->groups->count();
-
Remove member(s) from group
$group->leave([$userId, $userId2, ...]);
Posts
-
Create a post
$post = Groups::createPost($data);
Note : Acceptable values for Post $data array
$data = [
'title' => '',
'user_id' => 0,
'body' => '',
'type' => '',
'extra_info' => '',
];
-
Get post
$post = Groups::post($postId);
-
Update a post
$post->update($data);
-
Delete a post
$post->delete();
-
Add a post to a group
$group->attachPost($postId);
-
Add multiple posts to a group
$group->attachPost([$postId, $postId2, ...]);
-
Remove post from a group
$group->detachPost($postId);
-
Group posts
$posts = $group->posts;
$posts = $group->posts()->paginate(5);
$posts = $group->posts()->orderBy('id', 'DESC')->paginate(5);
-
User posts
$user = Groups::getUser($userId);
$posts = $user->posts;
Comments
Note : Acceptable values for Comment $data array
$data = [
'post_id' => 0,
'user_id' => 0,
'body' => '',
];
-
Add comment
$comment = Groups::addComment($data);
-
Get comment
$comment = Groups::comment($commentId);
-
Update a comment
$comment->update($data);
-
Delete a comment
$comment->delete();
Reporting
-
Report a comment or post
$comment->report($userIdOfReporter);
$post->report($userIdOfReporter);
-
Remove a post or comment report
$post->removeReport($userId);
$comment->removeReport($userId);
-
Toggle report/unreport a post or comment
$post->toggleReport($userId);
$comment->toggleReport($userId);
-
Post or Comment Report count
$commentReports = $comment->reportsCount;
$postReports = $post->reportsCount;
Likes
-
Like a post or comment
$post->like($userId);
$comment->like($userId);
-
Unlike a post or comment
$post->unlike($userId);
$comment->unlike($userId);
-
Toggle like/unlike a post or comment
$post->toggleLike($userId);
$comment->toggleLike($userId);
-
Post or Comment likes count
$postLikes = $post->likesCount;
$commentLikes = $comment->likesCount;