GithubHelp home page GithubHelp logo

daliendev / permission-group Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 368 KB

Permission Group for Laravel Nova allows for the management of various permission values within a single JSON column.

Home Page: https://packagist.org/packages/daliendev/permissiongroup

JavaScript 17.98% CSS 0.16% Vue 51.03% PHP 30.84%
laravel laravel-framework laravel-package laravel-nova laravel-nova-field

permission-group's Introduction

PermissionGroup Field

Prerequisites

  1. Laravel Nova 4 installed in your application
  2. Composer installed on your system

Installation

composer require daliendev/permissiongroup

Prepare your migrations

You will need a column in JSON format.

class CreateRolesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            ...
            $table->json('permissions')->nullable();
            ...
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('roles');
    }
}

Basic Usage

To use the PermissionGroup field in your Nova application, you need to add the field to your Nova resource. To do this, simply add the following code:

use Daliendev\PermissionGroup

public function fields(Request $request)
{
    return [
        ...
        PermissionGroup::make('Permissions', 'permissions')  
        ->on(User::class)  
        ->on(Role::class)  
        ...
    ];
}

This will display two CRUD oriented BooleanGroups and all the value will be stored in same {permissions} attribute/column of your model.

Custom permissions can also be specified (in addition to the CRUD on a resource and as an independent group):

    PermissionGroup::make('Permissions', 'permissions')  
        ->on(User::class, [  
            'test' => 'Test'  
        ])  
        ->on(Role::class)  
        ->with('Other', [
            'can_view_secret_page' => 'can view secret page'
        ])  
        ->with('Other2', [  
            'can_view_logs' => 'can view logs'  
        ]),

So permissions column of your role can store as much value as needed in JSON format:

["can_view_role", "can_view_user", "can_view_logs_other", "test_user"]

As all Laravel Nova Fields the following methods may be used to show / hide fields based on the display context:

    showOnIndex
    showOnDetail
    showOnCreating
    showOnUpdating
    showOnPreview
    showWhenPeeking
    hideFromIndex
    hideFromDetail
    hideWhenCreating
    hideWhenUpdating
    onlyOnIndex
    onlyOnDetail
    onlyOnForms
    exceptOnForms

For more details please refer to related Laravel Nova documentation page.

Some example screenshots:

Permission Group on Form page Permission Group on Detail page Permission Group on Index page


2023

permission-group's People

Contributors

daliendev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.