1. Go to this page and download the library: Download rs/laravel-doorman 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/ */
rs / laravel-doorman example snippets
// Give a permission to a role
$role->givePermissionTo('view users');
// Assign a user to a role
$user->assignRole($role);
// Check if a user has permission to
$user->can('view users');
use Illuminate\Foundation\Auth\User as Authenticatable;
use Redsnapper\LaravelDoorman\Models\Traits\HasPermissionsViaRoles;
class User extends Authenticatable
{
use HasPermissionsViaRoles;
// ...
}
$user->assignRole('writer');
// You can also assign multiple roles at once
$user->assignRole('editor', 'admin');
// or as an array
$user->assignRole(['editor', 'admin']);
$user->removeRole('editor');
// All current roles will be removed from the user and replaced by the array given
$user->syncRoles(['editor', 'admin']);
$user->hasPermissionTo('edit users'); // Name of permission
$user->hasPermissionTo($somePermission->id); // Id of permission
$user->hasPermissionTo($somePermission); // Permission Model
namespace App;
use Illuminate\Database\Eloquent\Model;
use Redsnapper\LaravelDoorman\Models\Contracts\Role as RoleContract;
use Redsnapper\LaravelDoorman\Models\Traits\HasPermissions;
class Role extends Model implements RoleContract
{
use HasPermissions;
}
namespace App;
use Illuminate\Database\Eloquent\Model;
use Redsnapper\LaravelDoorman\Models\Contracts\Permission as PermissionContract;
use Redsnapper\LaravelDoorman\Models\Traits\HasRoles;
use Redsnapper\LaravelDoorman\Models\Traits\PermissionIsFindable;
class Permission extends Model implements PermissionContract
{
use HasRoles, PermissionIsFindable;
}