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 Admin:

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

[!IMPORTANT] Prior to v3.1.0 Shield supported spatie/laravel-permission:^5.0 and now it supports version ^6.0. Which has some breaking changes around migrations. If you are upgrading from a version prior to v3.1.0 please make sure to remove the old migration file and republish the new one.

Installation

  1. Install the package via composer:

  2. Add the Spatie\Permission\Traits\HasRoles trait to your User model(s):

  3. Publish the config file then setup your configuration:

  4. Register the plugin for the Filament Panels you want

  5. Now run the following command to install shield:

Follow the prompts and enjoy!

Filament Panels

If you want to enable Shield for more than one panel then you need to register the plugin for each panel as mentioned above.

Panel Access

Shield comes with the HasPanelShield trait which provides an easy way to integrate Shield's conventions with the Filament's panel access system.

The HasPanelShield trait provides an implementation for the canAccessPanel method, determining access based on whether the user possesses the super_admin role or the panel_user role. It also assigns the panel_user role to the user upon creation and removes it upon deletion. Ofcourse the role names can be changed from the plugin's configuration file.

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 restricted 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

Role Policy

To ensure RoleResource access via RolePolicy you would need to add the following to your AuthServiceProvider:

You can skip it if you have enabled it from the config:

Policy 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:

Custom folder structure for Models or Third-Party Plugins

Shield also generates policies and permissions for third-party plugins and Models with custom folder structure and to enforce the generated policies you will need to register them in your application's AuthServiceProvider:

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:

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

Translations

Publish the translations using:

Available Filament Shield Commands

shield:doctor

shield:install

Setup Core Package requirements and Install Shield. Accepts the following flags:

shield:generate

Generate Permissions and/or Policies for Filament entities. Accepts the following flags:

shield:super-admin

Create a user with super_admin role.

shield:publish

shield:seeder

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 ....