5 use Illuminate\Database\Eloquent\Model;
7 class Role extends Model
10 protected $fillable = ['display_name', 'description'];
12 * Sets the default role name for newly registered users.
15 protected static $default = 'viewer';
18 * The roles that belong to the role.
20 public function users()
22 return $this->belongsToMany('BookStack\User');
26 * The permissions that belong to the role.
28 public function permissions()
30 return $this->belongsToMany('BookStack\Permission');
34 * Check if this role has a permission.
37 public function hasPermission($permission)
39 return $this->permissions->pluck('name')->contains($permission);
43 * Add a permission to this role.
44 * @param Permission $permission
46 public function attachPermission(Permission $permission)
48 $this->permissions()->attach($permission->id);
52 * Get an instance of the default role.
55 public static function getDefault()
57 return static::getRole(static::$default);
61 * Get the role object for the specified role.
65 public static function getRole($roleName)
67 return static::where('name', '=', $roleName)->first();