Passed
Push — dev5 ( c3531a...a24f56 )
by Ron
08:14
created

Customers::ParentCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Customers extends Model
9
{
10
    use SoftDeletes;
11
12
    protected $primaryKey = 'cust_id';
13
    protected $fillable   = ['cust_id', 'parent_id', 'name', 'dba_name', 'address', 'city', 'state', 'zip', 'active'];
14
    protected $hidden     = ['created_at', 'deleted_at', 'updated_at'];
15
    protected $appends    = ['child_count'];
16
    protected $casts      = [
17
        'deleted_at' => 'datetime:M d, Y',
18
    ];
19
20 16
    public function CustomerSystems()
21
    {
22 16
        return $this->hasMany('App\CustomerSystems', 'cust_id', 'cust_id');
23
    }
24
25 26
    public function getChildCountAttribute()
26
    {
27 26
        return Customers::where('parent_id', $this->cust_id)->count();
28
    }
29
30 2
    public function ParentCustomer()
31
    {
32 2
        return $this->hasOne('App\Customers', 'cust_id', 'parent_id');
33
    }
34
}
35