Download the PHP package philsquare/permissions without Composer

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

Philsquare Permissions

A Laravel package for managing role-based permissions through policies. Define permissions declaratively in your policies and sync them to your database with a single command.

Requirements

Upgrading from an earlier version? See UPGRADE.md.

Installation

The service provider is auto-registered via Laravel's package discovery.

Setup Spatie Permissions

If you haven't already, publish and run the Spatie migrations:

Add the HasRoles trait to your User model:

Quick Start

1. Create a Policy

Use the artisan command with the --withPermissions flag:

Or add permissions to an existing policy by extending BasePolicy:

2. Sync Permissions to Database

Run the refresh command whenever you add or modify permissions:

This command:

The sync runs in one transaction, so requests keep seeing the old permissions until the new ones are ready, and a failure changes nothing. A role that no policy declares ends up with no permissions.

3. Assign Roles to Users

Use Spatie's methods to assign roles:

4. Check Permissions

Use Laravel's built-in authorization:

How It Works

Permission Naming Convention

Permissions are stored in kebab-case format: {model}:{action}

Policy Method Database Permission
PostPolicy::viewAny() post:view-any
PostPolicy::create() post:create
PostPolicy::forceDelete() post:force-delete
PurchaseOrderPolicy::updateEta() purchase-order:update-eta

The first part comes from the policy's class name, without its folder. App\Policies\Billing\InvoicePolicy uses invoice:*, so two policies with the same name in different folders share their permissions.

The before() Hook

When you extend BasePolicy, the before() method automatically checks if the user's roles have the required permission. If the permission exists, it returns null (allowing the policy method to execute). If not, it returns false (denying access).

This means your policy methods define the logic for when an action should be allowed, and the role-permission mapping controls who can attempt it.

Only permissions held through a role count. A permission given directly to a user with givePermissionTo() doesn't pass this check.

To add your own check in front of the role check, override before() and call the parent:

Policy Method Return Values

Your policy methods should return true or false based on business logic:

The before() hook runs first. If the user lacks the permission, they're denied immediately. If they have the permission, your method's logic determines the final result.

Permission Helpers

The permissions() method provides helpers for building permission lists. Each one returns an array.

Helpers take policy method names exactly as written, so use deleteDraft, not delete-draft. A name that doesn't match a method is dropped without warning, which leaves the role without that permission.

all()

Returns all public methods from the policy (excluding system methods):

crud(array $additional = [])

Returns standard CRUD methods plus any additional methods:

only(array $methods)

Returns only the specified methods:

except(array $methods)

Returns all methods except the specified ones:

Full Example

Filament

The package works with Filament 5 panels as they are, but Filament treats policies differently from plain Laravel in two ways that matter here.

Abilities a policy doesn't define

When a policy has no method for an ability, Filament doesn't call the policy, so before() never runs. It allows the action instead. A role with no delete access would still be able to use the DeleteBulkAction in every generated resource.

The package closes this for policies extending BasePolicy:

Ability the policy leaves out What the user needs
deleteAny, restore, forceDelete The permission for delete
restoreAny The permission for restore, or for delete if the policy has no restore()
forceDeleteAny The permission for forceDelete, or for delete if the policy has no forceDelete()
replicate The permission for create
reorder The permission for update
viewAny, view, create, update, delete Denied until the policy defines it

So a role that can delete can also restore and permanently delete, until you say otherwise. To separate them, define forceDelete() on the policy, which makes it a permission of its own.

An app's own Gate::before() callback, such as a super admin check, still takes priority. So does any ability you've defined with Gate::define().

Policies generated with --withPermissions define all of these abilities, so each one is its own permission that you grant explicitly. That also means they work with Filament's strictAuthorization():

Bulk actions and record rules

Filament checks deleteAny once for the whole selection, so any record-level logic in your delete() method doesn't run for bulk deletes. If delete() has rules like "only drafts", ask Filament to check each record:

Or turn this on for every bulk delete in a service provider:

Commands

permissions:refresh

Syncs all role permissions from policies to the database. Run this after:

If it finds no policies, it warns you and changes nothing.

make:policy --withPermissions

Creates a new policy that extends BasePolicy, with a method for every ability Filament uses. --model is required, because the generated methods need it:

Deployment

Add permissions:refresh to your deploy script to ensure permissions stay in sync:

This ensures any new permissions added in the release are automatically synced to the database without manual intervention.

Defining Roles

Roles are created automatically when you run permissions:refresh. Any role name used in a rolePermissions() array will be created if it doesn't exist.

For better organization, you can define roles in an enum:

Then use it in your policies:

Claude Code Plugin

This package includes a Claude Code plugin that provides AI-assisted permission implementation.

Features

Autonomous Implementation: When you create a new policy in a project using this package, the plugin's agent will proactively offer to add role-based permissions - extending BasePolicy and implementing rolePermissions() with appropriate helpers.

Skill Knowledge: The plugin provides Claude with knowledge about permission helpers, naming conventions, and best practices so it can correctly implement permissions without documentation lookups.

Commands:

Installation

The plugin lives in this package's GitHub repository, which is also a plugin marketplace. In Claude Code, run:

To set it up for everyone working on a project, commit this to the project's .claude/settings.json instead:

The plugin comes from the repository's default branch, so it describes the latest release.

Plugin Structure

Using the Plugin

Once the plugin is enabled, Claude uses it when you work on policies. When creating policies, Claude will:

  1. Detect the package is installed
  2. Extend BasePolicy instead of Laravel's base policy
  3. Add the rolePermissions() method with appropriate role mappings
  4. Remind you to run permissions:refresh

License

MIT


All versions of permissions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
laravel/framework Version ^12.0|^13.0
spatie/laravel-package-tools Version ^1.92
spatie/laravel-permission Version ^8.3
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 philsquare/permissions contains the following files

Loading the files please wait ...