PHP code example of daliendev / permissiongroup

1. Go to this page and download the library: Download daliendev/permissiongroup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daliendev / permissiongroup example snippets


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');
    }
}

use Daliendev\PermissionGroup

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

    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'  
        ]),