Groups
This package allows you to add user groups system to your Laravel 5 application, (*1)
Installation
From the command line, run:, (*2)
composer require lifeids/groups
Add the service provider to your config\app.php
the providers array, (*3)
Lifeids\Groups\GroupsServiceProvider
You can use the facade for shorter code. Add this to your aliases:, (*4)
'Groups' => Lifeids\Groups\Facades\GroupsFacade::class` to your `config\app.php
The class is bound to the ioC as Groups, (*5)
$groups = App::make('Groups');
Publish the assets:, (*6)
php artisan vendor:publish
This will publish database migrations., (*7)
Groups
Create a group
$group = Groups::create($userId, $data);
Accepted fields in $data array, (*8)
$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
];
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);
Acceptable values for Post $data array, (*9)
$data = ['title', 'user_id', '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;
Acceptable values for Comment $data array, (*10)
$data = ['post_id', 'user_id', 'body'];
$comment = Groups::addComment($data);
$comment = Groups::comment($commentId);
$comment->update($data);
$comment->delete();
Reporting
$comment->abuseReport($userIdOfReporter);
$post->abuseReport($userIdOfReporter);
$post->removeAbuseReport($userId);
$comment->removeAbuseReport($userId);
$post->toggleAbuseReport($userId);
$comment->toggleAbuseReport($userId);
$commentReports = $comment->reportsCount;
$postReports = $post->reportsCount;
Likes
$post->like($userId);
$comment->like($userId);
$post->unlike($userId);
$comment->unlike($userId);
$post->toggleLike($userId);
$comment->toggleLike($userId);
$postLikes = $post->likesCount;
$commentLikes = $comment->likesCount;