Download the PHP package rivalex/clearance without Composer

On this page you can find all versions of the php package rivalex/clearance. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package clearance

--- ### **A complete permissions, roles & contextual authorization panel for Laravel** [![Latest Version on Packagist](https://img.shields.io/packagist/v/rivalex/clearance.svg)](https://packagist.org/packages/rivalex/clearance) [![PHP Version](https://img.shields.io/badge/PHP-8.3%2B-blue)](https://php.net) [![Laravel Version](https://img.shields.io/badge/Laravel-12--13-orange)](https://laravel.com) [![License](https://img.shields.io/github/license/rivalex/clearance)](LICENSE.md) [![codecov](https://codecov.io/github/rivalex/clearance/branch/master/graph/badge.svg?token=ogc9M1neEf)](https://codecov.io/github/rivalex/clearance) [![Tests](https://github.com/rivalex/clearance/actions/workflows/run-tests.yml/badge.svg)](https://github.com/rivalex/clearance/actions/workflows/run-tests.yml) A drop-in admin panel for Laravel applications built on top of [spatie/laravel-permission](https://github.com/spatie/laravel-permission). Adds a Livewire 4 + Flux UI panel with contextual authorization and role ceilings - installable with one artisan command, without altering any Spatie table.

## [Official Documentation](https://rivalex.github.io/clearance-docs/)

What Clearance gives you

Requirements

Dependency Version
PHP ^8.3
Laravel ^12.0 | ^13.0
spatie/laravel-permission ^6.0
livewire/livewire ^3.0 | ^4.0
livewire/flux ^2.14

Installation

Run the installer:

Always run clearance:install, never a plain php artisan migrate on a fresh setup. Clearance's own migrations depend on Spatie's roles/permissions tables existing first; the installer publishes and runs Spatie's migrations before its own. If you migrate directly and Spatie isn't set up yet, you'll get an actionable error message telling you to run the installer instead.

Optional flags:

Flag Description
--user=ID Assign the super_admin role to a user after install
--role=NAME Assign clearance-access to a role (created if absent)
--super-admin-role=NAME Promote an existing role to super_admin (skips interactive prompt)
--force Re-run even if already installed

What the installer does:

  1. Publishes config/clearance.php.
  2. Publishes Clearance's migrations.
  3. Detects Spatie Permission tables - if the roles table is absent, publishes and runs Spatie's migrations automatically first.
  4. Runs all pending migrations.
  5. Creates clearance-access and all 5 fine-grained capability permissions: clearance-permissions-write, clearance-roles-write, clearance-guards-write, clearance-settings-write, clearance-users-write.
  6. Creates the super_admin role with all clearance-* permissions assigned (additive - never removes existing permissions on re-run).
  7. Writes storage/.clearance-installed as an idempotency marker.

Migrating from an existing Spatie install? Use php artisan clearance:backfill (see docs/migration-from-spatie.md first - important notes on super_admin collision, custom model subclasses, and guard import.


⚠️ Required: add HasClearance to your User model

To use contextual authorization methods ($user->canIn(), $user->hasRoleIn()), add the HasClearance trait to App\Models\User. It already includes Spatie's HasRoles - one line replaces both:

Already using use HasRoles? Replace it with use HasClearance, or keep both - PHP deduplicates trait composition automatically, no conflicts.

Without this trait, $user->canIn() and related methods are unavailable, but the Blade directives (@canin, @hasrolein) and ContextService keep working regardless (they don't depend on the trait).


Quick Start

Option A - Pre-built routes

After installation the panel is available at /clearance (or the configured route_prefix). All routes are protected by the clearance.access middleware and use the host app's Livewire layout automatically.

URI Route name Description
/clearance clearance.home Dashboard
/clearance/guards clearance.guards Guard management (create/edit/delete)
/clearance/permissions clearance.permissions Permission CRUD with group-prefix naming validation
/clearance/roles clearance.roles Role CRUD with guard-scoped permission assignment, scope (global/contextual), and ceiling
/clearance/settings clearance.settings Display metadata (icons, colors), default role, general settings
/clearance/user/{userId} clearance.user Per-user role assignment + contextual permission overrides (requires modules.users = true)

Route names stay stable regardless of prefix changes. To customize middleware:

Option B - Embedded Livewire components

Each panel section can be mounted individually inside any Blade view, Filament page, or custom route:


Contextual Authorization

Clearance extends Spatie's global authorization model with context-scoped checks. A user's roles can be assigned within a specific context (e.g. a Store, Tenant, or Project) and are invisible outside that scope.

On the User model

In Blade views

Both directives resolve safely (return false) for a guest user - they never throw.

Via ContextService (advanced)

For use in controllers, policies, or jobs where the User model may not have the trait:

Or via the Clearance facade, which delegates to the same service:

How resolution works

resolveFor() merges three sources, in this precedence order:

  1. Contextual role grants - permissions from roles the user holds specifically within this context (clr_role_ctx).
  2. Global role grants - permissions from the user's globally-assigned Spatie roles (so super_admin and other global roles satisfy canIn() for any context).
  3. Per-context overrides (clr_ctx_overrides) - forced_on adds a permission on top of the above; forced_off removes it, even if the permission was granted by a global role. A deny always wins.

Super Admin

The super_admin role is created automatically by clearance:install and kept in sync with all clearance-* permissions.

Gate bypass (opt-in)

super_admin_gate_bypass controls whether the super_admin role bypasses all Laravel can() / Gate::allows() / policy checks globally, via a Gate::before() hook.

Default: false. The bypass is opt-in. To enable it:

When enabled, any user holding super_admin skips all Gate checks application-wide - not only Clearance panel checks. For a narrower scope, leave it off and grant permissions explicitly.

Alias detection

If your database already contains a role named super_admin, superadmin, super-admin, root, or owner, the installer detects it and prompts you interactively to promote it or create a separate super_admin. Use --super-admin-role=NAME to skip the prompt:

Promotion renames the role in place - all existing model_has_roles assignments are preserved via the FK on role_id.


Panel Access & Fine-grained write permissions

Navigate to /clearance after installation. Read access to the whole panel requires the clearance-access permission (checked via can(), never hasRole()):

Write operations on each section are gated by a dedicated, delegable permission - all created by clearance:install and assigned to super_admin:

Permission Controls
clearance-permissions-write Create / edit / delete permissions
clearance-roles-write Create / edit / delete roles and their permission assignments
clearance-guards-write Create / edit / delete guards
clearance-settings-write Edit display metadata, icons, colors, default role
clearance-users-write Assign / remove roles for a specific user

If a fine-grained permission row doesn't exist at all in the database (a legacy pre-seeding state), the check falls back to clearance-access for backwards compatibility. On any instance that has run clearance:install, this fallback never activates.

clearance-* permissions are reserved: they cannot be created, renamed, deleted, or added to any role except through the package's own install flow - even by a super_admin actor for the super_admin role itself.


Roles

Scope: global vs. contextual

Every role declares a scope at creation time:

Roles without an explicit RoleMeta row default to global for backwards compatibility.

Ceiling roles

A role can declare a ceiling - a parent role whose permission set acts as an upper bound:

This is configured per-role in the Roles panel (RoleForm), or programmatically via RoleService::setParent() / removeParent().


Guards

Guards can be managed from the panel and are injected into auth.guards at application boot, so they're recognized by Laravel's auth system before any request runs. Only drivers in the allow-list are accepted:

A guard with an unlisted driver is skipped at boot (with a log warning) rather than corrupting the auth config.


Users module (opt-in)

Disabled by default. Enable it in config/clearance.php:

Navigate to /clearance/user/{userId} to manage a specific user's roles and permissions. Access requires clearance-access (read) and clearance-users-write (assign/remove).

What the panel does

Both role assignment and direct/override permission grants enforce a privilege ceiling: a non-super_admin actor cannot modify their own assignments, and cannot grant a permission they don't themselves hold.

Linking to the panel from your app

Contextual roles under the hood

Authorization checks respect the context via $user->canIn(), @canin, and ContextService.


Settings

The Settings panel (clearance-settings-write to edit) lets you configure:


Dashboard

The Dashboard shows at-a-glance stats: total roles, guards, and permissions; the number of distinct permission groups (by naming prefix); the number of contextual role assignments; and the top 5 roles ranked by user count.


Permission Naming Convention

Permissions must follow the group-action format:

Disable enforcement per environment:

The separator itself (- or _) is validated at boot - it's the only piece of this config that reaches a raw SQL fragment (grouping/sorting permissions), so only those two characters are accepted.


Configuration

Publish the config:

config/clearance.php reference:

Key Default Purpose
route_prefix 'clearance' URI prefix for all panel routes.
middleware ['web', 'auth'] Applied to all panel routes before clearance.access.
access_permission 'clearance-access' Permission checked by the access middleware.
user_model null Defaults to auth.providers.users.model.
modules.users false Master switch for the Users module (routes + Livewire components).
contextual_models [] FQCN => ['label', 'icon', 'label_attribute', 'searchable'] - models that can act as role-binding contexts.
enforce_naming_convention true Enforce group-action permission naming.
naming_separator '-' Separator character - '-' or '_' only.
guards [] Override auto-detected guards from config/auth.php. Empty = auto-detect all.
allowed_guard_drivers ['session', 'token', 'jwt', 'passport', 'sanctum'] Drivers accepted when injecting DB guards into auth.guards.
layout null Blade layout for full-page components. null = host app's default (config('livewire.component_layout')).
auto_assign_default_role false Auto-assign the Settings-configured default role on Registered event.
super_admin_gate_bypass false Opt-in: super_admin bypasses all Gate checks application-wide.
ui.flux_pro null null = auto-detect via Flux::pro().
dark_mode.force env('CLEARANCE_FORCE_DARK_MODE', false) Always render Clearance's dark theme regardless of the host app or OS color scheme. Overridable live from the Settings UI (Appearance card), which takes precedence over this default.

Appearance

Clearance's own CSS uses a class-based dark: variant (&:where(.dark, .dark *)), so it normally follows the host app's <html class="dark"> ancestor - the same convention as Tailwind's default class strategy. If your host app has no class-based dark toggle (or its state doesn't match the real OS/browser preference), Clearance's own styling can render unstyled even though the rest of the page looks fine.

Set force to true (or CLEARANCE_FORCE_DARK_MODE=true) to always render Clearance's dark theme, regardless of the host app or OS color scheme - useful when embedding Clearance in a host with no dark-mode toggle, or while developing locally on a light-mode system. Can also be toggled live from the Appearance card in /clearance/settings, which takes precedence over this config default.


Database

Clearance owns 6 tables and never alters Spatie's core tables (roles, permissions, model_has_roles, model_has_permissions, role_has_permissions). All FKs referencing roles.id/permissions.id cascade on delete unless noted; Spatie tables have no FKs pointing back to clr_*.

Table Key columns
clr_meta subject_type, subject_key (unique together) · display_name, description, icon_svg, color - display metadata for a role or guard
clr_role_meta role_id (unique, FK → roles) · is_locked, scope (global|contextual), context_types (json) · parent_role_id (nullable FK → roles, ON DELETE SET NULL) - ceiling role
clr_guards name (unique), driver, provider - guards managed via the panel
clr_settings key (unique), value - runtime key/value store (default role, etc.)
clr_role_ctx user_id, role_id (FK → roles), context_type, context_id - contextual role assignments, unique per (user, role, context_type, context_id)
clr_ctx_overrides user_id, role_id (FK → roles), permission_id (FK → permissions), context_type, context_id, type (forced_on|forced_off) - per-user, per-context permission overrides

Extending the package


i18n

9 languages ship out of the box: ar, en, es, fr, hi, it, pt, ru, zh (resources/lang/{locale}/ui.php). All locales expose an identical key set, verified by a dedicated test on every change.

To add or override a language, publish the translation files:

This copies them to lang/vendor/clearance/{locale}/ui.php in your app. Add a new locale directory there, using en/ui.php as the canonical key reference.


Migrating from an existing Spatie install

If your application already uses spatie/laravel-permission with existing roles, permissions, and assignments, clearance:install detects and preserves them - it never runs Spatie's migrations if the roles table already exists.

Backfill Clearance-specific metadata for pre-existing Spatie data:

All sections are idempotent. Full guide, including super_admin collision handling and custom model subclass notes: docs/migration-from-spatie.md.


Security

Clearance went through a dedicated pre-publication security audit plus two follow-up hardening passes before this release. Highlights: privilege-escalation ceilings on every permission-granting path (direct grants and role-level syncing alike), deny-authoritative context overrides, an allow-list SVG sanitizer, a protected clearance-* permission namespace, and guest-safe Blade directives.

Full audit trail, findings, and fixes: docs/plans/security-audit/plan.md.

Found a vulnerability? Please report it privately to the maintainer rather than opening a public issue.


Tips & Gotchas

Testing

370 tests, 1054 assertions - covering commands, services, Livewire components, contextual authorization, ceiling roles, and i18n key-parity across all 9 bundled languages.

License

MIT - see LICENSE.md.


All versions of clearance with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0||^13.0
livewire/flux Version ^2.14
livewire/livewire Version ^3.0||^4.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-permission Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rivalex/clearance contains the following files

Loading the files please wait ...