Completed
Push — master ( 4fea39...872a00 )
by Troy
01:28
created

BaseTenantModel::getTableName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MultiTenantLaravel\App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
abstract class BaseTenantModel extends Model
8
{
9
    /**
10
     * Construct the model with the provided config settings
11
     * or use our fallbacks if none are provided
12
     */
13
    public function __construct(array $attributes = [])
14
    {
15
        $this->setTable(config('multi-tenant.table_name'));
16
17
        $this->setFillable();
18
19
        // parent construct must go below property customizations
20
        parent::__construct($attributes);
21
    }
22
23
    /**
24
     *  Merge the fillable fields with any provided in the extending class
25
     */
26
    public function setFillable()
27
    {
28
        $fillable = [
29
            'owner_id',
30
            'slug',
31
            'name'
32
        ];
33
34
        $this->fillable(array_merge($this->fillable, $fillable));
35
    }
36
37
    /**
38
     *  Merge the fillable fields with any provided in the extending class
39
     */
40
    public function owner()
41
    {
42
        return $this->belongsTo(config('multi-tenant.user_class'), 'owner_id');
43
    }
44
}
45