5 use Illuminate\Database\Eloquent\Model;
7 class Role extends Model
10 protected $fillable = ['display_name', 'description'];
13 * The roles that belong to the role.
15 public function users()
17 return $this->belongsToMany('BookStack\User');
21 * The permissions that belong to the role.
23 public function permissions()
25 return $this->belongsToMany('BookStack\Permission');
29 * Check if this role has a permission.
32 public function hasPermission($permission)
34 return $this->permissions->pluck('name')->contains($permission);
38 * Add a permission to this role.
39 * @param Permission $permission
41 public function attachPermission(Permission $permission)
43 $this->permissions()->attach($permission->id);
47 * Get the role object for the specified role.
51 public static function getRole($roleName)
53 return static::where('name', '=', $roleName)->first();