| @@ 7-50 (lines=44) @@ | ||
| 4 | ||
| 5 | use Illuminate\Database\Eloquent\Model; |
|
| 6 | ||
| 7 | abstract class BasePermission extends Model |
|
| 8 | { |
|
| 9 | public $table = 'multi_tenant_permissions'; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * The attributes that are mass assignable. |
|
| 13 | * |
|
| 14 | * @var array |
|
| 15 | */ |
|
| 16 | protected $fillable = [ |
|
| 17 | 'name', 'label', 'feature_id', 'description', |
|
| 18 | ]; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The permissions relationship |
|
| 22 | */ |
|
| 23 | public function roles() |
|
| 24 | { |
|
| 25 | return $this->belongsToMany( |
|
| 26 | config('multi-tenant.role_class'), |
|
| 27 | 'multi_tenant_permission_multi_tenant_role', |
|
| 28 | 'multi_tenant_permission_id', |
|
| 29 | 'multi_tenant_role_id' |
|
| 30 | ); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Give the perimssion to the provided role |
|
| 35 | * |
|
| 36 | * @param BaseRole $role |
|
| 37 | * |
|
| 38 | * @return void |
|
| 39 | */ |
|
| 40 | public function giveToRole(BaseRole $role) |
|
| 41 | { |
|
| 42 | $this->roles()->syncWithoutDetaching([$role->id]); |
|
| 43 | ||
| 44 | return $this; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Check if the permission belongs to the given role |
|
| 49 | * |
|
| 50 | * @param BaseRole $role |
|
| 51 | * |
|
| 52 | * @return boolean |
|
| 53 | */ |
|
| @@ 7-50 (lines=44) @@ | ||
| 4 | ||
| 5 | use Illuminate\Database\Eloquent\Model; |
|
| 6 | ||
| 7 | abstract class BaseRole extends Model |
|
| 8 | { |
|
| 9 | public $table = 'multi_tenant_roles'; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * The attributes that are mass assignable. |
|
| 13 | * |
|
| 14 | * @var array |
|
| 15 | */ |
|
| 16 | protected $fillable = [ |
|
| 17 | 'name', 'label', 'description', |
|
| 18 | ]; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The permissions relationship |
|
| 22 | */ |
|
| 23 | public function permissions() |
|
| 24 | { |
|
| 25 | return $this->belongsToMany( |
|
| 26 | config('multi-tenant.permission_class'), |
|
| 27 | 'multi_tenant_permission_multi_tenant_role', |
|
| 28 | 'multi_tenant_role_id', |
|
| 29 | 'multi_tenant_permission_id' |
|
| 30 | ); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Assign the given permission to the role |
|
| 35 | * |
|
| 36 | * @param BasePermission $permission |
|
| 37 | * |
|
| 38 | * @return void |
|
| 39 | */ |
|
| 40 | public function assignPermission(BasePermission $permission) |
|
| 41 | { |
|
| 42 | $this->permissions()->syncWithoutDetaching([$permission->id]); |
|
| 43 | ||
| 44 | return $this; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Check if the role has the given permission |
|
| 49 | * |
|
| 50 | * @param BasePermission $permission |
|
| 51 | * |
|
| 52 | * @return boolean |
|
| 53 | */ |
|