lifeids / groups

Laravel 5 user groups package



This package allows you to add user groups system to your Laravel 5 application


From the command line, run:

composer require lifeids/groups

Add the service provider to your config\app.php the providers array


You can use the facade for shorter code. Add this to your aliases:

'Groups' => Lifeids\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.


Create a group
$group = Groups::create($userId, $data);

Accepted fields in $data array

$data = [
        '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
Update a group
Get user instance with group relations
$user = Groups::getUser($userId); 
Add members to group
$group->addMembers([$userId, $userId2, ...]);
Request to join a group
Accept a group request
Decline a group request
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, ...]);


Create a post
$post = Groups::createPost($data);

Acceptable values for Post $data array

$data = ['title', 'user_id', 'body', 'type', 'extra_info'];
Get post
$post = Groups::post($postId);
Update a post
Delete a post
Add a post to a group
Add multiple posts to a group
$group->attachPost([$postId, $postId2, ...]);
Remove post from a group
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

$data = ['post_id', 'user_id', 'body'];
Add comment
$comment = Groups::addComment($data);
Get comment
$comment = Groups::comment($commentId);
Update a comment
Delete a comment


Abuse Report a comment or post
Remove a post or comment abuse report
Toggle abuse report/unreport a post or comment
Post or Comment Report count
$commentReports = $comment->reportsCount;
$postReports = $post->reportsCount;


Like a post or comment
Unlike a post or comment
Toggle like/unlike a post or comment
Post or Comment likes count
$postLikes = $post->likesCount;
$commentLikes = $comment->likesCount;