Download the PHP package bezhansalleh/filament-shield without Composer

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

filament-shield-art

FILAMENT 8.x Packagist Tests Passing Code Style Passing Downloads

Shield

The easiest and most intuitive way to add access management to your Filament Panels.

Features

Requirements

[!NOTE] For Filament 2.x use 2.x branch

Table of Contents - [Shield](#shield) - [Features](#features) - [Requirements](#requirements) - [Installation](#installation) - [1. Install Package](#1-install-package) - [2. Configure Auth Provider](#2-configure-auth-provider) - [3. Setup Shield](#3-setup-shield) - [4. Install for Panel](#4-install-for-panel) - [Usage](#usage) - [Configuration](#configuration) - [Resources](#resources) - [Default](#default) - [Custom Permissions](#custom-permissions) - [Configure Permission Identifier](#configure-permission-identifier) - [Custom Navigation Group](#custom-navigation-group) - [Pages](#pages) - [Pages Hooks](#pages-hooks) - [Pages Redirect Path](#pages-redirect-path) - [Widgets](#widgets) - [Policies](#policies) - [Path](#path) - [Policy Discovery](#policy-discovery) - [Using Laravel 10](#using-laravel-10) - [Using Laravel 11](#using-laravel-11) - [Users (Assigning Roles to Users)](#users-assigning-roles-to-users) - [Layout Customization](#layout-customization) - [Available Commands](#available-commands) - [Prohibited Commands](#prohibited-commands) - [Core Commands](#core-commands) - [Generate Command Options](#generate-command-options) - [Translations](#translations) - [Testing](#testing) - [Changelog](#changelog) - [Contributing](#contributing) - [Security Vulnerabilities](#security-vulnerabilities) - [Credits](#credits) - [License](#license)

Installation

1. Install Package

2. Configure Auth Provider

2.1. Publish the config and setup your auth provider model.

2.2 Add the HasRoles trait to your auth provider model:

3. Setup Shield

3.1 Without Tenancy:

3.2 With Tenancy:

This command will:

4. Install for Panel

The install command will register the plugin for your panel automatically. Choose the appropriate installation method:

4.1 Without Tenancy:

Or instead of the above command you can register the plugin manually in your xPanelProvider:

4.2 With Tenancy:

Or instead of the above command you can register the plugin and enable tenancy manually in your xPanelProvider:

This command will:

Usage

Configuration

See config/filament-shield.php for full configuration options.

Resources

Generally there are two scenarios that shield handles permissions for your Filament resources.

Default

Out of the box Shield handles the predefined permissions for Filament resources. So if that's all that you need you are all set. If you need to add a single permission (for instance lock) and have it available for all your resources just append it to the following config key:

:bulb: Now you are thinking what if I need a permission to be only available for just one resource? No worries, that's where Custom Permissions come to play.

Custom Permissions

To define custom permissions per Resource your Resource must implement the HasShieldPermissions contract. This contract has a getPermissionPrefixes() method which returns an array of permission prefixes for your Resource.

Consider you have a PostResource and you want a couple of the predefined permissions plus a new permission called publish_posts to be only available for PostResource only.

In the above example the getPermissionPrefixes() method returns the permission prefixes Shield needs to generate the permissions.

βœ… Now to enforce publish_post permission headover to your PostPolicy and add a publish() method:

πŸ…°οΈ/🈯️ To make the prefix translatable, publish Shield's translations and append the prefix inside resource_permission_prefixes_labels as key and it's translation as value for the languages you need.

Configure Permission Identifier

By default the permission identifier is generated as follow:

So for instance if you have a resource like App\Filament\Resources\Shop\CategoryResource then the permission identifier would be shop::category and then it would be prefixed with your defined prefixes or what comes default with shield.

If you wish to change the default behaviour, then you can call the static configurePermissionIdentifierUsing() method inside a service provider's boot() method, to which you pass a Closure to modify the logic. The Closure receives the fully qualified class name of the resource as $resource which gives you the ability to access any property or method defined within the resource.

For example, if you wish to use the model name as the permission identifier, you can do it like so:

Warning Keep in mind that ensuring the uniqueness of the permission identifier is now up to you.

Custom Navigation Group

By default the english translation renders Roles and Permissions under 'Filament Shield' if you wish to change this, first publish the translations files and change the relative locale to the group of your choosing for example:

to

apply this to each language you have groups in.

Pages

If you have generated permissions for Pages you can toggle the page's navigation from sidebar and restrict access to the page. You can set this up manually but this package comes with a HasPageShield trait to speed up this process. All you have to do is use the trait in you pages:

πŸ“• HasPageShield uses the booted method to check the user's permissions and makes sure to execute the booted page method in the parent page if exists.

Pages Hooks

However if you need to perform some methods before and after the booted method you can declare the next hooks methods in your filament page.

Pages Redirect Path

HasPageShield uses the config('filament.path') value by default to perform the shield redirection. If you need to overwrite the rediretion path, just add the next method to your page:

Widgets

if you have generated permissions for Widgets you can toggle their state based on whether a user have permission or not. You can set this up manually but this package comes with a HasWidgetShield trait to speed up this process. All you have to do is use the trait in you widgets:

Policies

Path

If your policies are not in the default Policies directory in the app_path() you can change the directory name in the config file:

Policy Discovery

Got a ton of policies inside subdirectories? Have to manually register them! right?

Well, you can or you could instruct Laravel to automatically detect and register policiesβ€”even in subdirectories for you.

Just add this to the boot() method:

πŸ“Œ Laravel 10 β†’ AuthServiceProvider

πŸ“Œ Laravel 11+ β†’ xxServiceProvider.

Third-Party Plugins Policies

Shield also generates policies and permissions for third-party plugins. To enforce the generated policies you will need to register them.

Using Laravel 10
Using Laravel 11

Users (Assigning Roles to Users)

Shield does not come with a way to assign roles to your users out of the box, however you can easily assign roles to your users using Filament Forms's Select or CheckboxList component. Inside your users Resource's form add one of these components and configure them as you need:

  1. Without Tenancy

  2. With Tenancy

You can find out more about these components in the Filament Docs

Layout Customization

You can easily customize the Grid, Section and CheckboxList's columns() and columnSpan() without publishing the resource.

Screenshot 2023-09-24 at 10 34 31 PM

Available Commands

Prohibited Commands

Since almost all shield commands are destructive and can cause data loss, they can be prohibited by calling the prohibit method of the command as following in a service provider's boot() method:

Core Commands

Generate Command Options

[!NOTE] For setting up super-admin user when using tenancy/team feature consult the core package spatie/laravel-permission

Translations

Publish the translations using:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of filament-shield with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
filament/filament Version ^3.2
spatie/laravel-package-tools Version ^1.9
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 bezhansalleh/filament-shield contains the following files

Loading the files please wait ....