5 use Illuminate\Database\Eloquent\Model;
7 class Role extends Model
10 * Sets the default role name for newly registered users.
13 protected static $default = 'viewer';
16 * The roles that belong to the role.
18 public function users()
20 return $this->belongsToMany('BookStack\User');
24 * The permissions that belong to the role.
26 public function permissions()
28 return $this->belongsToMany('BookStack\Permission');
32 * Add a permission to this role.
33 * @param Permission $permission
35 public function attachPermission(Permission $permission)
37 $this->permissions()->attach($permission->id);
41 * Get an instance of the default role.
44 public static function getDefault()
46 return static::getRole(static::$default);
50 * Get the role object for the specified role.
54 public static function getRole($roleName)
56 return static::where('name', '=', $roleName)->first();