GateServiceProvider class

The Gate Service Provider.

This provider is responsible for registering authorization abilities and policies. Extend this class to customize gate definitions.

Usage

  1. Create your provider:
class AppGateServiceProvider extends GateServiceProvider {
  AppGateServiceProvider(super.app);

  @override
  Future<void> boot() async {
    await super.boot();

    // Register super admin bypass
    Gate.before((user, ability) {
      if (user.isAdmin) return true;
      return null;
    });

    // Register abilities
    Gate.define('update-post', (user, post) => user.id == post.userId);
    Gate.define('delete-post', (user, post) => user.isAdmin);

    // Or use policies
    PostPolicy().register();
    CommentPolicy().register();
  }
}
  1. Register in config/app.dart:
'providers': [
  (app) => AppGateServiceProvider(app),
],
Inheritance

Constructors

GateServiceProvider(MagicApp app)
Create a new Gate service provider.

Properties

app MagicApp
Reference to the application container.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

boot() Future<void>
Bootstrap any application services.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register() → void
Register any application services.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited