Installation
Requirements
- PHP 8.2+
- Laravel 11, 12 or 13
- Livewire 3 or 4 — only required if you use the bundled admin UI
1. Require the package
composer require henry-ht/laravel-bitwise-permission
2. Run the installer
php artisan bwp:install
This single command:
- Publishes
config/bitwise-permission.php. - Publishes the migration that creates the package tables.
- Publishes the package's CSS assets.
- Runs
php artisan migrate(with a confirmation prompt, unless--migrateis passed). - Seeds base roles, permissions, routes and menus (with a confirmation prompt, unless
--seedis passed).
Non-interactive install, useful in CI or deploy scripts:
php artisan bwp:install --migrate --seed --force
| Option | Description |
|---|---|
--migrate |
Run migrations without prompting |
--seed |
Seed base data without prompting |
--force |
Overwrite already-published files |
Manual installation
If you'd rather run each step yourself:
php artisan vendor:publish --tag=bwp-config
php artisan vendor:publish --tag=bwp-migrations
php artisan vendor:publish --tag=bwp-assets
php artisan migrate
php artisan db:seed --class="HenryHt\BitwisePermission\Database\Seeders\BitwisePermissionSeeder"
Or publish everything in one go:
php artisan vendor:publish --tag=bwp-all
Wiring up the User model
Add role_id to the users table
php artisan make:migration add_role_id_to_users_table --table=users
// up()
Schema::table('users', function (Blueprint $table) {
$table->foreignId('role_id')
->nullable()
->constrained('bwp_roles')
->nullOnDelete();
});
// down()
Schema::table('users', function (Blueprint $table) {
$table->dropConstrainedForeignId('role_id');
});
If you changed
table_prefixin the config, reference{prefix}rolesinstead ofbwp_roles.
Add the trait
use HenryHt\BitwisePermission\Traits\HasPermissionsTrait;
class User extends Authenticatable
{
use HasPermissionsTrait;
protected $fillable = ['name', 'email', 'password', 'role_id'];
}
The trait registers everything: can*() checks, isSuperAdmin(), permission and menu management. See Permissions for the full method list.
Middleware is registered automatically
The package registers the bwp.permission middleware alias for you — nothing to add to bootstrap/app.php. Use it directly on your routes:
Route::middleware('bwp.permission')->group(function () {
// protected routes
});
To use a different alias, change it in the config:
'middleware' => [
'alias' => 'bwp.permission',
],
See Middleware for how the view prerequisite and additional bits work.
Next steps
- Define
bits,base_permissionsandsuper_admin_rolein the config — see Configuration. - Define
role_permissionsper role. - Define who can access the admin UI via
gate. - Run
php artisan bwp:sync-routesto register your project's named routes. - Run
php artisan db:seedagain if you added roles, permissions or menus. - Visit
/bwp/accessesto review access per role, and/bwp/menus/rolesto configure menu visibility.
For a complete walk-through, see Examples.