1. Go to this page and download the library: Download techgonia/pbac 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/ */
techgonia / pbac example snippets
use Pbac\Traits\HasPbacAccessControl;
use Pbac\Traits\HasPbacGroups;
use Pbac\Traits\HasPbacTeams;
class User extends Authenticatable
{
use HasPbacAccessControl, HasPbacGroups, HasPbacTeams;
}
use Pbac\Models\PBACAccessControl;
use Pbac\Facades\Pbac;
// Grant permission
PBACAccessControl::factory()
->allow()
->forUser($user)
->forResource(Post::class, $post->id)
->withAction('edit')
->create();
// Or use the Facade
Pbac::allow()
->forUser($user)
->forResource(Post::class, $post->id)
->withAction('edit')
->create();
// Check permission
if ($user->can('edit', $post)) {
// User can edit this post
}
// Or use the Facade
if (Pbac::can($user, 'edit', $post)) {
// User can edit this post
}
// Even with high priority allow...
PBACAccessControl::factory()->allow()->withPriority(1000)->create();
// ...a low priority deny wins
PBACAccessControl::factory()->deny()->withPriority(1)->create();
// Result: Access DENIED (secure by default)