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// 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 211Permission::set('post.create', 'Create a new post', 'en');12 13// Way 314Permission::set('post.create', [15 'ar' => ['title' => 'إنشاء منشور جديد'],16 'en' => ['title' => 'Create a new post']17]);
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(...);