Groupable is a Laravel package for grouping content.
It takes its inspiration from the Drupal community - think of it as a simplified Organic Groups for Laravel.
The idea of Groupable is to turn any Eloquent model into a group which can be 'joined' by users and act as a container for 'content'.
Addtionally, users may be given additional group roles on a group-by-group basis.
Groupable works by adding traits to the models within your application that you wish to adopt this group like behaviour.
Groupable provides three traits which can be added to your models:
The IsGroup trait is added to a model which you would like to be treated as a group.
The IsGroupable trait is added to models which you would like to be treated as group content.
The JoinsGroups trait is added to your User model.
In fact, only the IsGroup trait is necessary in order to obtain group funtionality. However, the IsGroupable and JoinsGroups traits provide useful group related functionality to your user model and groupable content types.
Groupable includes a class called Groupable which offers internal helper methods. You likely won't need to use this class unless you intend to modify the code within this project yourself.
Groupable requires 3 tables to be added to your schema and includes database migrations out of the box.
There is no need to publish these migrations to your project as the accompanying service provider points to the migrations folder within your Composer vendor folder.
The table structure is as follows:
Installation is via composer:
Then be sure to include the GroupableServiceProvider in you a app config file:
Finally, run the migrations:
Creating a Group
Simply use the IsGroup trait in the model that you wish to become a group:
$groupable_models should be an array containing the fully-qualified class name of the models which should be allowed to be grouped within this group. Groupable will throw an exception if you attempt to add a content type not specified here to the group.
$groupable_roles should be an array containing the names of additional roles that you wish members to be grantable to members of this group.
Creating Groupable content
Only models specified within the $groupable_models property on your group model may be added to a given group.
To add additional functionality use the IsGroupable trait on the model that represents your groupable content.