Preface
Introduction
A Platform 4 extension to manage roles across your application.
Have a read through the Installation Guide.
Features
- Can create & manage roles.
- Can set name & slug of role.
- Can set role permissions.
- Can add attributes to role.
Examples
The $roles
variable used below is a reference to the UserRepository.
$roles = app('platform.roles');
Retrieve all roles
$allUsers = $roles->findAll();
Dynamically create a new role
$roles->create([
'email' => 'foo@example.com',
'password' => 'secret',
]);
Setup
Installation
The best and easiest way to install the Roles extension is with Composer.
Preparation
Open your composer.json
file and add the following to the require
array:
"platform/roles": "3.0.*"
Add the following lines after the require
array on your composer.json
file:
"repositories": [
{
"type": "composer",
"url": "https://packages.cartalyst.com"
}
]
Note: Make sure that after the required changes your
composer.json
file is valid by runningcomposer validate
.
Install the dependencies
Run Composer to install or update the new requirement.
php composer install
or
php composer update
Now you are able to install the extension through Platform's admin.
Usage
In this section we'll show how you can manage your application's roles.
Repository
IoC Binding
The role repository is bound to platform.roles
and can be resolved out of the IoC Container using that offset.
$roles = app('platform.roles');
Methods
The repository contains several methods that are used throughout the extension, most common methods are listed below.
For an exhaustive list of available methods, checkout the RoleRepositoryInterface
- findAll();
Returns a collection of all roles.
- find($id);
Returns a role object based on the given id.
- create(array $data);
Creates a new role.
- update($id, array $data);
Updates an existing role.
- delete($id);
Deletes a role.