Daravel

daravel_permission

English ยท Bahasa Indonesia

Roles and permissions in the database for Daravel, on the five tables of spatie/laravel-permission v6: a Laravel application using Spatie and a Daravel application share them, and a role given by either is seen by the other.

dart pub add daravel_permission
// bootstrap/app.dart
import 'package:daravel_permission/daravel_permission.dart';

Application createApp() => Application.configure(basePath: '.')
    .withPermissions()
    .withMigrations([...migrations, const CreatePermissionTables()])
    // ...
    .create();

final class User extends Model with AuthenticatableModel, HasRoles { /* ... */ }
await user.assignRole('writer');
await user.hasPermissionTo('posts.edit');
router.get('/admin', admin.index).middleware(['auth', 'role:admin|editor']);
  • HasRoles, Role and Permission with Spatie's methods, exceptions and 403 messages; the role, permission and role_or_permission middleware; a gate hook, so Gate.allows and can: see permissions.
  • Guards, opt-in wildcards (posts.*) and super-admin role, and the permission:* commands.
  • An in-memory cache: a check is a set lookup, and changes reach every isolate and process (every server, with a shared cache store) within a second.
  • Tested on SQLite, PostgreSQL and MariaDB, and against Laravel 12 with Spatie 6.

Documentation: github.com/daravel-dev/daravel/blob/main/docs/guide/permissions.md.

License and trademarks

MIT. "Laravel" is a trademark of Laravel Holdings Inc.; "Dart" is a trademark of Google LLC. spatie/laravel-permission is Spatie's MIT-licensed package; Daravel only shares its database layout. Daravel is an independent project, not affiliated with or endorsed by any of them.

Libraries

commands
The permission:* commands, for bootstrap/commands.dart:
daravel_permission
Roles and permissions in the database for Daravel (Blueprint #36), on spatie/laravel-permission's tables, so a Laravel application can share them.