Download the PHP package codelabmw/teams without Composer
On this page you can find all versions of the php package codelabmw/teams. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codelabmw/teams
More information about codelabmw/teams
Files in codelabmw/teams
Package teams
Short Description Provides team management logic to be paired with any UI framework.
License MIT
Informations about the package teams
Teams
A laravel package from Codelab that handles team management business logic onbehalf of your laravel application. It can be used with any UI framework.
The main purpose of the package is to provide resource sharing as well as compartmentalization of the shared resources.
Installation
To add the package in your laravel project run the following command.
composer require codelabmw/teams
After the installation, run the following command to publish the migration and config files.
php artisan vendor:publish --tag=codelab-teams
And then run the following command to create necessary tables.
php artisan migrate
Usage
Creating a team
To start creating teams, in your model acting as a team entity (the model of your choice to have teams) add the HasTeam
trait.
Once you have your entity configured you can then create teams using the teams relationship method or the provided helper method.
-
Using the team's entity
teams
relationship method. - Using the team's entity
createTeam
helper method.
The create
or createTeam
functions expects the following fields.
name: The team name. Required.
slug: Usually the name in lowercase and hyphanated. Optional.
description: An optional description of the team. Optional.
status: An integer between 1 and 2 indicating whether the team is active or inactive respectively. Defaults to 1 (Active). You can the Status enum provided by the package.
You can find a comprehensive list of helper methods here
Adding members to team
To add a member to a team first you have to add the IsMember
trait to your model acting as a member entity.
By default the package will assume that the App\Models\User
class is the member entity. This behavior can be changed in the config file, specify your own member entity class on the member
attribute.
Once you have your member entity configured, you can proceed to add members to a team by using either of the following options.
-
Using the team's object
members
relationship method. -
Using the team's object
addMember
helper method.The
addMember
method requires the members id as an int or string. -
Using the member's object
joinTeam
helper method.The
joinTeam
method requires the teams id as an int or string.
You can find a comprehensive list of helper methods here
Adding resources to team
Because the package does not know how many and what kind of resources your application will have, things have to be done manually. Following are the steps to adding resource sharing.
First add the IsResource
trait to the resource entity (model class acting as a resource) in your application.
Secondly extend the base Codelab\Teams\Models\Team
class in a custom team class.
To let the package know of the new custom class, change the team
attribute in the config file.
And then finally create a relationship between the resource and the team in the new custom team class using the morphByResource
method.
Once all this is done you can go ahead to add resources to team objects using the relationship method you just created.
Glossary
Helper methods
On the object that has teams
On a team object
On a member object
On a resource object
Thank you for checking out the package, don't forget to share and :star2: if you liked it :grin:.