PHP code example of tannhatcms / permissionmanager

1. Go to this page and download the library: Download tannhatcms/permissionmanager 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/ */

    

tannhatcms / permissionmanager example snippets


 namespace App\Models;

use Backpack\CRUD\app\Models\Traits\CrudTrait; // <------------------------------- this one
use Spatie\Permission\Traits\HasRoles;// <---------------------- and this one
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable
{
    use CrudTrait; // <----- this
    use HasRoles; // <------ and this

    /**
     * Your User Model content
     */

// in some ServiceProvider, AppServiceProvider for example

$this->app->bind(
    \Backpack\PermissionManager\app\Http\Controllers\UserCrudController::class, //this is package controller
    \App\Http\Controllers\Admin\UserCrudController::class //this should be your own controller
);

// this tells Laravel that when UserCrudController is requested, your own UserCrudController should be served.
shell
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
php artisan migrate
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
// then, add the Spatie\Permission\Traits\HasRoles trait to your User model(s)
bash
php artisan vendor:publish --provider="Backpack\PermissionManager\PermissionManagerServiceProvider" --tag="config" --tag="migrations"
bash
php artisan migrate
config/backpack/permissionmanager.php
resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
menu.blade.php
config/backpack/base.php
config/backpack/base.php
config/auth.php
 bash
backpack_user()->givePermissionTo('edit articles');
 bash
backpack_user()->revokePermissionTo('edit articles');
 bash
backpack_user()->hasPermissionTo('edit articles');
 bash
backpack_user()->can('edit articles');
 bash
backpack_user()->can('edit articles');
config/backpack/permissionmanager.php
config/backpack/permissionmanager.php
routes/backpack/permissionmanager.php
config/backpack/base.php