Pharaonic
Loading...

OLD VERSION

WARNING : You're browsing the documentation for an old version of Users. Consider upgrading your project to 2.x

# Roles

Most of medium/big projects needs to users roles so we provide to you the easy way.

# Creation

You can create multilingual role, you can use the way that you prefer.

1use Pharaonic\Laravel\Users\Models\Roles\Role;
2 
3// Way 1
4Role::create('admin', 'Administrator');
5 
6// Way 2
7Role::create('admin', 'Administrator', 'en');
8 
9// Way 3
10Role::create('admin', [
11 'ar' => 'إداري',
12 'en' => 'Administrator'
13]);

# Permissions

Attach permission to the role.

1use Pharaonic\Laravel\Users\Models\Roles\Role;
2 
3$role = Role::findByCode('admin');
4$role->permit('post.create', 'post.edit', 'post.delete');

# Inclusion

This is how you can include the role into your user model.

1namespace App\Models;
2 
3use Pharaonic\Laravel\Users\Traits\HasRoles;
4 
5class User extends Authenticatable
6{
7 use HasRoles;
8}

# entrust

Giving the user one or many roles.

1$user->entrust('DevOps', 'Developer');
2// Returns Boolean

# entrusted

Check if the user has all these roles.

1$user->entrusted('DevOps');
2// Returns Boolean

# entrustedAny

Check if the user has one of these roles.

1$user->entrustedAny(['Developer', 'Musician']);
2// Returns Boolean

# distrust

Distrusting the user from having these roles.

1$user->distrust('Musician');
2// Returns Boolean

# distrusted

Check if the user has not all these roles.

1$user->distrusted(['CEO', 'CFO']);
2// Returns Boolean

# distrustedAny

Check if the user has not one of these roles.

1$user->distrustedAny(['CEO', 'CFO', 'Musician']);
2// Returns Boolean

# syncRoles

section/laravel/users.47.

1$user->syncRoles('CEO', 'Developer', 'Musician');
2// Returns Boolean

# Middlewares

You can use middlewares to strict your routes.

1Route::middleware('entrusted:CFO')->group(...);
2Route::middleware('entrustedAny:CFO,CEO')->group(...);

# Attributes

  • rolesList

# Blade Directives

  • entrusted
  • entrustedAny
  • distrusted
  • distrustedAny