This package allows you to add user groups system to your Laravel 5 application
From the command line, run:
composer require musonza/groups
Add the service provider to your config\app.php
the providers array
Musonza\Groups\GroupsServiceProvider
You can use the facade for shorter code. Add this to your aliases:
'Groups' => Musonza\Groups\Facades\GroupsFacade::class` to your `config\app.php
The class is bound to the ioC as Groups
$groups = App::make('Groups');
Publish the assets:
php artisan vendor:publish
This will publish database migrations.
$group = Groups::create($userId, $data);
Accepted fields in $data array
$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);
Acceptable values for Post $data array
$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;
Acceptable values for Comment $data array
$data = ['post_id', 'user_id', '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;