PHP code example of mohamedmohamedhekal / guardrail

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

    

mohamedmohamedhekal / guardrail example snippets


use Hekal\GuardRail\Concerns\HasGuardRail;

class User extends Authenticatable
{
    use HasGuardRail;
}

use Hekal\GuardRail\Facades\GuardRail;

$team = GuardRail::createTeam('Acme', 'acme');
GuardRail::createAbility('Edit orders', 'orders.edit');
GuardRail::createRole('Editor', $team, ['orders.edit'], 'editor');

GuardRail::assignRole($user, 'editor', $team);
GuardRail::can($user, 'orders.edit', $team); // true

Route::middleware('guardrail.ability:orders.edit,acme')->group(...);

GuardRail::startImpersonation($admin, $customer, reason: 'ticket #12', ttlMinutes: 30);
// switch auth in the host app using the target user
GuardRail::stopImpersonation(); // writes ended_at + clears session markers
bash
composer vendor:publish --tag=guardrail-config
php artisan migrate