### Install Permissions for Laravel via Composer and publish migrations Source: https://github.com/roundly-consulting/permissions-for-laravel/blob/main/README.md Run these commands to install the package, publish its migrations, and run them. Requires PHP 8.4 and Laravel 12 or 13. If your users have UUID/ULID keys, set PERMISSIONS_KEY_TYPE (uuid or ulid) before migrating. ```bash composer require roundly-consulting/permissions-for-laravel php artisan vendor:publish --tag="permissions-migrations" php artisan migrate ``` -------------------------------- ### Add HasRoles trait to user model Source: https://github.com/roundly-consulting/permissions-for-laravel/blob/main/README.md Use the HasRoles trait on your authenticatable user model to enable roles and permissions. This example shows a typical User class extending Authenticatable. ```php use Illuminate\Foundation\Auth\User as Authenticatable; use RoundlyConsulting\Permissions\Concerns\HasRoles; class User extends Authenticatable { use HasRoles; } ``` -------------------------------- ### Register permissions, create role, and assign role Source: https://github.com/roundly-consulting/permissions-for-laravel/blob/main/README.md Use the Permissions facade to find or create permissions, bundle them into a role, and assign that role to a user. The permission() method finds or creates, and givePermissionTo accepts multiple permission names. ```php use RoundlyConsulting\Permissions\Facades\Permissions; Permissions::permission('posts.view'); // find or create Permissions::permission('posts.edit'); Permissions::role('editor')->givePermissionTo('posts.view', 'posts.edit'); Permissions::for($user)->assignRole('editor'); ``` -------------------------------- ### Check permissions with hasRole, getAllPermissions, and can middleware Source: https://github.com/roundly-consulting/permissions-for-laravel/blob/main/README.md Check roles and permissions on the user model. Laravel's Gate answers for every registered permission, and the can middleware can be used on routes. The getAllPermissions() method returns direct and role-based permissions. ```php $user->hasRole('editor'); // true $user->getAllPermissions()->pluck('name'); // direct + via roles: posts.view, posts.edit $user->can('posts.edit'); // true Route::get('/posts', PostsController::class)->middleware('can:posts.view'); ```