Most of medium/big projects needs to users permissions so we provide to you the easy way.
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 310Permission::create('post.create', [11 'ar' => 'إنشاء منشور جديد',12 'en' => 'Create a new post'13]);
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 Authenticatable6{7 use HasPermissions; 8}
Giving the user one or many permissions.
1$user->permit('post.create', 'post.edit');2// Returns Boolean
Check if the user has all these permissions.
1$user->permitted(['post.create', 'post.delete']);2// Returns Boolean
Check if the user has one of these permissions.
1$user->permittedAny(['post.create', 'post.delete']);2// Returns Boolean
Forbid the user to have these permissions.
1$user->forbid('post.edit', 'post.view');2// Returns Boolean
Check if the user has not all these permissions.
1$user->forbad(['post.create', 'post.delete']);2// Returns Boolean
Check if the user has not one of these permissions.
1$user->forbadAny(['post.create', 'post.delete']);2// Returns Boolean
Clear all user permissions and give him/her these list.
1$user->syncPermissions('post.*', 'article.*');2// Returns Boolean
You can use middlewares to strict your routes.
1Route::middleware('permitted:post.create,post.edit')->group(...);2Route::middleware('permittedAny:post.create,post.edit')->group(...);