Simply define the permission in the filament resource.

Overview

Simply define the permissions in the filament resource.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Easily define permissions for Filament Resources & Relation Managers

Installation

You can install the package via composer:

composer require z3d0x/filament-simple-permissions

This package does not require any additional configuration after installation

Usage

This package comes with two traits HasResourcePermissions and HasRelationManagerPermissions, which can be used in Filament's Resources and RelationManagers respectively.

To use simply use the trait in your Resource/RelationManger and define your permissions.

Resource Example

//UserResource.php
use Z3d0X\FilamentSimplePermissions\Concerns\HasResourcePermissions;

class UserResource extends Resource
{
    use HasResourcePermissions;

    protected static array $permissions = [
        'viewAny' => 'access-users',
        'view' => 'access-users',
        'create' => 'create-users',
        'update' => 'update-users',
        'delete' => ['update-users', 'delete-stuff'], //use an array if multiple permissions are needed
        'deleteAny' => false, //also supports boolean, to allow/disallow for all users
    ];
}

RelationManager Example

//PostsRelationManager.php
use Z3d0X\FilamentSimplePermissions\Concerns\HasRelationManagerPermissions;

class PostsRelationManager extends HasManyRelationManager
{
    use HasRelationManagerPermissions;

    protected static array $permissions = [
        'create' => 'create-posts',
        'update' => 'update-posts',
        'delete' => ['update-posts', 'delete-stuff'], //use an array if multiple permissions are needed
        'deleteAny' => false, //also supports boolean, to allow/disallow for all users

        //Supports relation manager specific actions.
        'viewForRecord' => 'access-posts',
        'associate' => 'update-posts',
        'dissociate' => 'update-posts',
        'dissociateAny' => false,
    ];
}

Advanced Usage

For advanced usage, it is possible to define a static getPermissions() method, instead of $permissions property

//PostsRelationManager.php
use Z3d0X\FilamentSimplePermissions\Concerns\HasRelationManagerPermissions;
use Illuminate\Database\Eloquent\Model;

class PostsRelationManager extends HasManyRelationManager
{
    use HasRelationManagerPermissions;

    protected static function getPermissions(): array
    {
        return [
            'viewForRecord' => fn (Model $ownerRecord) => $ownerRecord->user_id === auth()->id(),
            'update' => function (Model $record) {
                return $record->user_id === auth()->id();
            },
        ];
    }
}

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.

You might also like...
Add a general-purpose tools page to your Filament project. đź› 
Add a general-purpose tools page to your Filament project. đź› 

Add a general-purpose tools page to your Filament project. Installation You can install the package via Composer: composer require ryangjchandler/fila

 The Most Popular JavaScript Calendar as a Filament Widget đź’›
The Most Popular JavaScript Calendar as a Filament Widget đź’›

The Most Popular JavaScript Calendar as a Filament Widget đź’› Features Accepts all configurations from FullCalendar Event click and drop events Upcomin

A single-field repeater for Filament. ⚡️

A single-field repeater for Filament. This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Insta

A convenient helper for using the laravel-seo package with Filament Admin and Forms
A convenient helper for using the laravel-seo package with Filament Admin and Forms

Combine the power of Laravel SEO and Filament PHP. This package is a convenient helper for using the laravel-seo package with Filament Admin and Forms

Easily interact and control your feature flags from Filament

Easily interact and control your feature flags from Filament

Build structured navigation menus in Filament.

Build structured navigation menus in Filament. This plugin for Filament provides a Navigation resource that allows to build structural navigation menu

Access laravel log through Filament admin panel
Access laravel log through Filament admin panel

Access laravel log through Filament admin panel Features Syntax highlighting Quickly jump between start and end of the file Refresh log contents Clear

A collection of reusable components for Filament.
A collection of reusable components for Filament.

A collection of reusable components for Filament. This package is a collection of handy components for you to use in all your Filament projects. It pr

Social login for Filament through Laravel Socialite
Social login for Filament through Laravel Socialite

Social login for Filament through Laravel Socialite Add OAuth login through Laravel Socialite to Filament. Installation You can install the package vi

Comments
Releases(v1.0.0)
Owner
Ziyaan
Full Stack Web Developer - TALL Stack
Ziyaan
This package provides a Filament resource to view all Laravel sent emails.

This package provides a Filament resource to view all Laravel outgoing emails. It also provides a Model for the database stored emails. Installation Y

RamĂłn E. Zayas 22 Jan 2, 2023
Filament-spatie-laravel-activitylog - View your activity logs inside of Filament. ⚡️

View your activity logs inside of Filament. This package provides a Filament resource that shows you all of the activity logs created using the spatie

Ryan Chandler 45 Dec 26, 2022
Create and manage A Domain Driven Design (DDD) in your Laravel app, simply and efficiently.

Create and manage A Domain Driven Design (DDD) in your Laravel app, simply and efficiently.

Lucas Nepomuceno 4 Jun 11, 2022
Laravel telegram log is a package that can catch your logs all quite simply

Laravel Telegram log Laravel telegram log is a package that can catch your logs all quite simply. Requirments This package is tested with Laravel v8 i

Muath Alsowadi 4 Aug 3, 2022
Implementation Package Spatie/Laravel-Permission

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

M Rizal 3 Sep 12, 2021
CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen

Description This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application. The package is based on Framework agnostic (PS

null 48 Feb 1, 2020
Lightweight JSON:API resource for Laravel

JSON:API Resource for Laravel A lightweight Laravel implementation of JSON:API. This is a WIP project currently being built out via livestream on my Y

Tim MacDonald 241 Jan 5, 2023
Trait for multilingual resource file support

⚡ Usage This library supports MultilingualResourceTrait which can be used in PluginBase. Multilingual support of resource files is possible using this

PocketMine-MP projects of PresentKim 1 Jun 7, 2022
⚙️Laravel Nova Resource for a simple key/value typed setting

Laravel Nova Resource for a simple key/value typed setting Administer your Laravel Simple Setting in Nova Pre-requisites This Nova resource package re

elipZis 5 Nov 7, 2022
A simple profile management page for Filament. ✨

A simple profile page for Filament. This package provides a very simple Profile page that allows the current user to manage their name, email address

Ryan Chandler 65 Jan 5, 2023