Completed
Push — master ( 872a00...e2f753 )
by Troy
01:33
created

BasePermission::roles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MultiTenantLaravel\App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7 View Code Duplication
abstract class BasePermission extends Model
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
     *  Assign a given permission to the Role
35
     */
36
    public function giveToRole(BaseRole $role)
37
    {
38
        $this->roles()->syncWithoutDetaching([$role->id]);
39
40
        return $this;
41
    }
42
43
    /**
44
     *  Check if the role has a given permission
45
     */
46
    public function hasRole(BaseRole $role)
47
    {
48
        return $this->roles()->where('multi_tenant_role_id', $role->id)->exists();
49
    }
50
}
51