BaseFeature::tenants()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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