Skip to content

Roles and Permissions

Michele Angioni edited this page Feb 12, 2016 · 1 revision

Message Board comes with a role and permission system out of the box. You can manage them through the MbPermissions facade.

Default roles are Admin and Moderator. The first one can edit and delete posts and comments, ban users, add and remove moderators, manage Categories. The Moderator has the same Permissions of the admin, but manage moderators and categories.

The following methods are available:

Retrieve all roles

MbPermissions::getRoles()

Retrieve a Role

MbPermissions::getRole($idRole)

- $idRole is the Role id.

Create a new Role

MbPermissions::createRole($name, $permissions = [])

- $name is the name of the new Role
- $permissions can be an array of Permission ids or a Collection of Permissions

Retrieve all Permissions

MbPermissions::getPermissions()

Retrieve a Permission

MbPermissions::getPermission($idPermission)

- $idPermissionis the Permissionid.

Create a new Permission

MbPermissions::createPermission($name)

- $name is the Permission name.

Attach a Permission to a Role

MbPermissions::attachPermission($role, $permission)

- $role can be an id or a Role model
- $permission can be an id or a Permission model 

Detach a Permission from a Role

MbPermissions::detachPermission($role, $permission)

- $role can be an id or a Role model
- $permission can be an id or a Permission model 

To test an User against a Role, call

$user->hasMbRole($name)

where $name is the name of the Role.

If you want to test an user against a Permission, use

$user->canMb($permission)

where $permission is the name of the Permission.

Default provided permissions are:

  • "Edit Posts"
  • "Delete Posts"
  • "Ban Users"
  • "Add Moderators"
  • "Remove Moderators"
  • "Manage Permissions"
  • "Manage Categories"