PHP code example of tahmid / laravel-acl-manager

1. Go to this page and download the library: Download tahmid/laravel-acl-manager 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/ */

    

tahmid / laravel-acl-manager example snippets


use Tahmid\AclManager\Models\Role;

public function roles()
{
    return $this->belongsToMany(Role::class)
            ->withPivot(['is_active', 'is_primary', 'released_at'])
            ->withTimestamps();
}

public function hasPermission(string $slug): bool
{
    return $this->roles()
        ->whereHas('permissions', fn($q) => $q->where('slug', $slug)->orWhere('name', $slug))
        ->exists();
}

$ php artisan migrate

// config/acl.php

return [
    'dashboard_route' => '/dashboard',
    'superuser_column' => 'is_superuser',
];

// routes/web.php

Route::middleware('role_permission_check')->group(function () {
    //
});