Skip to content

Schemas

A schema is a Warrant\Schema\WarrantSchema subclass, one per resource. It declares the abilities that exist and the conditions a rule may test, and binds them to a model. A schema is vocabulary, not policy — it decides nothing.

use Warrant\Schema\WarrantSchema;
class DocumentSchema extends WarrantSchema
{
public const model = Document::class; // the Eloquent model this governs
// public const schemaKey = 'documents'; // optional override
}

const model binds the schema to an Eloquent model class. Warrant uses it to resolve a schema from a model (and vice versa) and to derive the schema key.

The schema key identifies the resource in rules, lookups, and middleware. By default it’s derived from the model’s table name:

public static function schemaKey(): string; // 'documents'

Override it with the schemaKey constant when you want a stable key independent of the table name.

Abilities are the verbs a rule can grant or deny. Declare each as a class constant marked #[Ability]. The constant’s value is the ability name used in rules; the constant’s name is irrelevant to Warrant (discovery is by attribute, not by naming).

use Warrant\Ability;
#[Ability] public const VIEW = 'view';
#[Ability] public const APPROVE = 'approve';
DocumentSchema::declaredAbilities(); // ['view', 'approve', ...]

A rule that names an ability the schema doesn’t declare is rejected — see Errors & exceptions for the two distinct “unknown ability” messages (one at rule-set validation, one at check time).

Warrant ships Warrant\StandardAbilities with common names if you want a shared vocabulary:

StandardAbilities::VIEW; // 'view'
StandardAbilities::CREATE; // 'create'
StandardAbilities::UPDATE; // 'update'
StandardAbilities::DELETE; // 'delete'
StandardAbilities::ARCHIVE; // 'archive'
StandardAbilities::CREATE_VIEW_UPDATE_DELETE; // ['create','view','update','delete']

Conditions are the predicates a rule may test. Each is a public method marked #[TargetedCondition] or #[GlobalCondition]. They’re covered in depth in Conditions.

For values known only at check time (the current tenant, an as-of date), a schema declares #[ContextKey] constants. See Check-time context.

A schema may govern a “section” with no model at all — for gating things like settings that only ever answer no-target checks:

class SettingsSchema extends WarrantSchema
{
public const model = ''; // no model
public const schemaKey = 'settings'; // REQUIRED when there's no model
#[Ability] public const MANAGE = 'manage';
// Only global conditions make sense here — targeted conditions
// are treated as false in a no-target check.
#[GlobalCondition]
public function isAdmin(GlobalConditionContext $c): bool
{
return (bool) $c->user->is_admin;
}
}

Targeted checks against a model-less schema throw; use capability checks instead.

Hook Purpose
protected function implicitRules(): array Rules always merged into every rule set — an admin escape hatch, a suspension lockout. See Resolvers.
protected function defaultContext(): array Default check-time context, merged under explicit values. See Check-time context.

Every schema must be listed in config/warrant.php. Unlisted schemas are unknown to lookups and middleware:

'schemas' => [
App\Warrant\DocumentSchema::class,
App\Warrant\SettingsSchema::class,
],