PHP code example of andheiberg / verify

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

    

andheiberg / verify example snippets


'providers' => array(
	'Toddish\Verify\VerifyServiceProvider'
),

'driver' => 'verify',

use Toddish\Verify\Models\User as VerifyUser;

class User extends VerifyUser
{
    // Code
}

$user = new Toddish\Verify\Models\User;
$role = new Toddish\Verify\Models\Role;
$permission = new Toddish\Verify\Models\Permission;

$role->permissions()->sync(array($permission->id, $permission2->id));

// Create a new Permission
$permission = new Toddish\Verify\Models\Permission;
$permission->name = 'delete_user';
$permission->save();

// Create a new Role
$role = new Toddish\Verify\Models\Role;
$role->name = 'Moderator';
$role->level = 7;
$role->save();

// Assign the Permission to the Role
$role->permissions()->sync(array($permission->id));

// Create a new User
$user = new Toddish\Verify\Models\User;
$user->username = 'Todd';
$user->email = '[email protected]';
$user->password = 'password'; // This is automatically salted and encrypted
$user->save();

// Assign the Role to the User
$user->roles()->sync(array($role->id));

// Using the public methods available on the User object
var_dump($user->is('Moderator')); // true
var_dump($user->is('Admin')); // false

var_dump($user->can('delete_user')); // true
var_dump($user->can('add_user')); // false

var_dump($user->level(7)); // true
var_dump($user->level(5, '&lt;=')); // false