Download the PHP package damianulan/laravel-sentinel without Composer

On this page you can find all versions of the php package damianulan/laravel-sentinel. 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 laravel-sentinel

Laravel Sentinel

Laravel

Laravel Sentinel is a context-aware roles and permissions package for Laravel.

Its core idea is simple:

This makes it useful for applications where a user may have one role in one model context and a different role elsewhere, for example per-project, per-campaign, or per-team access control.

Requirements

Installation

Install the package:

Publish the package assets:

Available publish tags:

Run the published migrations:

Generate the two application warden classes used to define your platform's roles and permissions:

Then synchronize those definitions into the database:

Run sentinel:run every time you add, remove, or change role and permission definitions.

How Sentinel Works

Sentinel has four main layers:

  1. Warden classes in App\Warden define your canonical roles and permissions as constants and configuration arrays.
  2. sentinel:run reads those classes and seeds the roles, permissions, and roles_permissions tables.
  3. Your authenticatable model uses Sentinel\Traits\HasRolesAndPermissions.
  4. Runtime checks use direct permissions, inherited role permissions, and optional model context.

Database Structure

Published migrations create these tables:

Important pivots:

That means a user can have the same role multiple times, each attached to a different context.

Setup

1. Add the trait to your user model

2. Define roles in App\Warden

Generated roles classes extend Sentinel\Config\Warden\RoleWarden.

Example:

Key methods:

3. Define permissions in App\Warden

Generated permissions classes extend Sentinel\Config\Warden\PermissionWarden.

Example:

Meaning of the assignment arrays:

Important distinction:

4. Seed the definitions

Once your warden classes exist:

What sentinel:run does:

Runtime API

The main runtime API lives on the model using HasRolesAndPermissions.

Role relationships and assignment

Roles are assigned either:

Example context model:

You can also assign by role ID or role model:

Revoke role assignments:

Inspect roles:

Direct permissions

Direct permissions are stored separately from role-based permissions.

Inspect direct permission assignments:

hasPermission() only checks direct permission assignments. It does not resolve inherited permissions or context.

Permission checks

Use hasPermissionTo() for the normal application-facing check.

It supports:

Examples:

Behavior notes:

Admin and root helpers

Query scopes

The trait also adds scopes:

withPermission() matches both direct permissions and permissions inherited through roles.

Contexts

Sentinel's distinguishing feature is context-aware role assignment.

The default context class is configured in config/sentinel.php:

The built-in System context implements Sentinel\Contracts\DefaultContext and returns key 0.

This means a role assigned without an explicit model context becomes a system-wide role:

To check permissions in a specific context:

You can replace the default context class in config as long as it implements Sentinel\Contracts\DefaultContext.

Gate Integration

Sentinel registers a Gate::before() callback in its service provider.

That means standard Laravel authorization checks can automatically resolve through hasPermissionTo() when the authenticated user exposes that method.

Examples:

The first Eloquent model found in the gate arguments is treated as the Sentinel context.

This makes Sentinel compatible with many normal Laravel authorization flows without writing a separate policy for every permission slug.

Blade Directives

Sentinel registers three Blade conditionals:

Models

Sentinel\Models\Role

Useful methods:

Relationships:

Sentinel\Models\Permission

Useful methods:

Relationships:

Configuration

Published config file: config/sentinel.php

Main options:

What these options control:

Cache Behavior

Sentinel caches the detected warden classes:

These values are flushed automatically when sentinel:run completes.

If you move or rename your App\Warden classes and want to clear cache manually, rerun:

Middleware

The package includes middleware classes:

Behavior:

Example registration in Laravel 11+:

Example usage:

If you need context-aware permission middleware, pass the appropriate argument pattern for your application or prefer standard Laravel gate checks inside controllers/services where the actual model instance is available.

Testing Helper

The package includes a small testing concern:

Typical Example

A user can be a global admin and also a project-scoped manager:

Another project will not automatically inherit the project-scoped role:

Warden Discovery Rules

Sentinel looks for role and permission wardens under App\Warden by scanning Composer's autoload classmap and finding concrete subclasses of:

If Sentinel cannot find one of these classes, it throws:

If class discovery seems stale after adding or renaming warden classes, refresh Composer autoload metadata:

Caveats

License

MIT. See LICENSE.

Contact

Questions and contributions: [email protected]


All versions of laravel-sentinel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
mews/purifier Version ^3.4
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 damianulan/laravel-sentinel contains the following files

Loading the files please wait ...