This package allows you to add user groups (groups, comment, like ...) system to your Laravel 5 application.
- 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 :
Note : is facultative.
'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:publishNote : 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
create_group_user_table // main relation User is in Group table
id
user_id
group_id
create_posts_table // users Posts table
id
title
body
type
user_id
extra_info
create_comments_table // users post Comments table
id
body
user_id
post_id
type
create_group_post_table // relation Group own Post table
group_id
post_id
create_likes_table // users Likes on comment or post
user_id
likeable_id
likeable_type
create_reports_table // Reporting post or comment
user_id
reportable_id
reportable_type
create_group_request_table // Request group attachement
user_id
group_id-
Adapt, Add, Remove, migrations for your usage.
-
Create migration, from the command line.
one-by-one :
php artisan make:migration create_migration_nameor all :
php artisan migrate$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
];$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);Note : Acceptable values for Post $data array
$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;Note : Acceptable values for Comment $data array
$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;