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

BaseFeature   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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
     *  The features relationship
28
     */
29
    public function giveToTenant(BaseTenant $tenant)
30
    {
31
        $this->tenants()->syncWithoutDetaching([$tenant->id]);
32
33
        return $this;
34
    }
35
36
    /**
37
     *  The features relationship
38
     */
39
    public function hasTenant(BaseTenant $tenant)
40
    {
41
        return $this->tenants()->where('tenant_id', $tenant->id)->exists();
42
    }
43
}
44