Pharaonic
Loading...

OLD VERSION

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

# Permissions

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

# Creation

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

1use Pharaonic\Laravel\Users\Models\Permissions\Permission;
2 
3// Way 1
4Permission::create('post.create', 'Create a new post');
5 
6// Way 2
7Permission::create('post.create', 'Create a new post', 'en');
8 
9// Way 3
10Permission::create('post.create', [
11 'ar' => 'إنشاء منشور جديد',
12 'en' => 'Create a new post'
13]);

# Inclusion

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

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

# permit

Giving the user one or many permissions.

1$user->permit('post.create', 'post.edit');
2// Returns Boolean

# permitted

Check if the user has all these permissions.

1$user->permitted(['post.create', 'post.delete']);
2// Returns Boolean

# permittedAny

Check if the user has one of these permissions.

1$user->permittedAny(['post.create', 'post.delete']);
2// Returns Boolean

# forbid

Forbid the user to have these permissions.

1$user->forbid('post.edit', 'post.view');
2// Returns Boolean

# forbad

Check if the user has not all these permissions.

1$user->forbad(['post.create', 'post.delete']);
2// Returns Boolean

# forbadAny

Check if the user has not one of these permissions.

1$user->forbadAny(['post.create', 'post.delete']);
2// Returns Boolean

# syncPermissions

Clear all user permissions and give him/her these list.

1$user->syncPermissions('post.*', 'article.*');
2// Returns Boolean

# Middlewares

You can use middlewares to strict your routes.

1Route::middleware('permitted:post.create,post.edit')->group(...);
2Route::middleware('permittedAny:post.create,post.edit')->group(...);

# Relationships

  • permissions

# Attributes

  • permissionsList

# Blade Directives

  • permitted
  • permittedAny
  • forbad
  • forbadAny