Role.php
985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace BookStack;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
/**
* Sets the default role name for newly registed users.
* @var string
*/
protected static $default = 'viewer';
/**
* The roles that belong to the role.
*/
public function users()
{
return $this->belongsToMany('BookStack\User');
}
/**
* The permissions that belong to the role.
*/
public function permissions()
{
return $this->belongsToMany('BookStack\Permission');
}
/**
* Add a permission to this role.
* @param Permission $permission
*/
public function attachPermission(Permission $permission)
{
$this->permissions()->attach($permission->id);
}
/**
* Get an instance of the default role.
* @return Role
*/
public static function getDefault()
{
return static::where('name', '=', static::$default)->first();
}
}