Pharaonic
Loading...

# 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// Code (string)
4// Title (string or array)
5// Locale (string) (only with string title)
6 
7// Way 1
8Permission::set('post.create', 'Create a new post');
9 
10// Way 2
11Permission::set('post.create', 'Create a new post', 'en');
12 
13// Way 3
14Permission::set('post.create', [
15 'ar' => ['title' => 'إنشاء منشور جديد'],
16 'en' => ['title' => 'Create a new post']
17]);

# 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