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