User Roles

Essentially, the Auth class offered by Laravel is already good enough for normal usage. Orchestra Platform only extends the default operation and allow a user to be link with one or many roles.

Default Roles

By default, Orchestra Platform require two user roles to be available. This roles can be modified, rename but it can't be deleted unless a different role is replaced as the default.

You can override the default config under resources/config/packages/orchestra/foundation/config.php (see Configuration for guide on publishing the config file).

<?php

return [
  
  /* ... */
  
	'roles' => [
    'admin' => 1,
    'member' => 2,
	],
];

Or access it from the Control Extension configuration page:

2032

Accessing the Roles

You can access the roles via eloquent:

<?php

use Orchestra\Model\Role;

$member = Role::member();

$admin = Role::admin();

Retrieving Roles

Retrieve user's roles is as simple as, which would return an instance of Illuminate\Support\Collection:

<?php

$roles = Auth::roles();

Checking Roles

There basically a few supported helpers to check roles:

is()

Check if user has all of the following roles.

<?php

if (Auth::is(['admin', 'editor'])) {
	echo "User is an admin and editor";
}

isAny()

Check if user is any of the following roles.

<?php

if (Auth::isAny(['member', 'admin'])) {
	echo "User is a member or admin";
}

isNot()

Check if user is not of the following roles.

<?php

if (Auth::isNot(['admin', 'editor'])) {
	echo "User isn't an admin and editor";
}

isNotAny()

Check if user has none any of the following roles.

<?php

if (Auth::isNotAny(['member', 'admin'])) {
	echo "User isn't a member or admin";
}