5 use Illuminate\Database\Eloquent\Model;
7 class Role extends Model
10 protected $fillable = ['display_name', 'description'];
13 * The roles that belong to the role.
15 public function users()
17 return $this->belongsToMany('BookStack\User');
21 * Get all related entity permissions.
22 * @return \Illuminate\Database\Eloquent\Relations\HasMany
24 public function entityPermissions()
26 return $this->hasMany(EntityPermission::class);
30 * The permissions that belong to the role.
32 public function permissions()
34 return $this->belongsToMany('BookStack\Permission');
38 * Check if this role has a permission.
41 public function hasPermission($permission)
43 return $this->permissions->pluck('name')->contains($permission);
47 * Add a permission to this role.
48 * @param Permission $permission
50 public function attachPermission(Permission $permission)
52 $this->permissions()->attach($permission->id);
56 * Detach a single permission from this role.
57 * @param Permission $permission
59 public function detachPermission(Permission $permission)
61 $this->permissions()->detach($permission->id);
65 * Get the role object for the specified role.
69 public static function getRole($roleName)
71 return static::where('name', '=', $roleName)->first();