]> BookStack Code Mirror - bookstack/blob - app/Role.php
Added basic system tests for markdown editor, Added extra test helpers
[bookstack] / app / Role.php
1 <?php
2
3 namespace BookStack;
4
5 use Illuminate\Database\Eloquent\Model;
6
7 class Role extends Model
8 {
9
10     protected $fillable = ['display_name', 'description'];
11
12     /**
13      * The roles that belong to the role.
14      */
15     public function users()
16     {
17         return $this->belongsToMany('BookStack\User');
18     }
19
20     /**
21      * The permissions that belong to the role.
22      */
23     public function permissions()
24     {
25         return $this->belongsToMany('BookStack\Permission');
26     }
27
28     /**
29      * Check if this role has a permission.
30      * @param $permission
31      */
32     public function hasPermission($permission)
33     {
34         return $this->permissions->pluck('name')->contains($permission);
35     }
36
37     /**
38      * Add a permission to this role.
39      * @param Permission $permission
40      */
41     public function attachPermission(Permission $permission)
42     {
43         $this->permissions()->attach($permission->id);
44     }
45
46     /**
47      * Get the role object for the specified role.
48      * @param $roleName
49      * @return mixed
50      */
51     public static function getRole($roleName)
52     {
53         return static::where('name', '=', $roleName)->first();
54     }
55 }