PHP code example of vdes / permision_roles

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

    

vdes / permision_roles example snippets


'providers' => [
    ....
    Vdes\PermisionRoles\PermissionsServiceProvider::class,
    ....
 ],

php vdes vendor:publish

php vdes migrate



namespace App\Models;

// tambah kode
use Vdes\PermisionRoles\Permissions\HasPermissionsTrait;
// end kode

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    ....
    // tambah ini HasPermissionsTrait pada use
    use HasFactory, Notifiable, HasPermissionsTrait ;
    ....
}

    protected $routeMiddleware = [
        ....
        'permission' => \Vdes\PermisionRoles\Middleware\PermissionMiddleware::class,
    ];


...

class NamaController extends Controller
{

    public function __construct()
    {
        $this->middleware('permission:namamodul-list',['only' => ['index']]);
        $this->middleware('permission:namamodultasks',['only' => ['store', 'create']]);
        $this->middleware('permission:namamodul-edit',['only' => ['edit','update']]);
        $this->middleware('permission:namamodul-delete',['only' => ['destroy']]);
    }

    ....
    
}

@role('namamodul-list')

@endrole