BaseFeature   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tenants() 0 4 1
A giveToTenant() 0 6 1
A hasTenant() 0 4 1
1
<?php
2
3
namespace MultiTenantLaravel\App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
abstract class BaseFeature extends Model
8
{
9
    /**
10
     * The attributes that are mass assignable.
11
     *
12
     * @var array
13
    */
14
    protected $fillable = [
15
        'name', 'model', 'label', 'description', 'auto_add'
16
    ];
17
18
    /**
19
     *  The features relationship
20
     */
21
    public function tenants()
22
    {
23
        return $this->belongsToMany(config('multi-tenant.tenant_class'));
24
    }
25
26
    /**
27
     * Give this feature to the provided tenant
28
     *
29
     * @param BaseTenant $tenant
30
     *
31
     * @return void
32
     */
33
    public function giveToTenant(BaseTenant $tenant)
34
    {
35
        $this->tenants()->syncWithoutDetaching([$tenant->id]);
36
37
        return $this;
38
    }
39
40
    /**
41
     * Confirm if a feature is activated for a given tenant
42
     *
43
     * @param BaseTenant $tenant
44
     *
45
     * @return boolean
46
     */
47
    public function hasTenant(BaseTenant $tenant)
48
    {
49
        return $this->tenants()->where('tenant_id', $tenant->id)->exists();
50
    }
51
}
52