Passed
Push — dev5a ( bf2271...c9bcfe )
by Ron
08:07
created

Customers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 30
ccs 6
cts 8
cp 0.75
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A CustomerSystems() 0 3 1
A ParentCustomer() 0 3 1
A ParentSystems() 0 3 1
A getChildCountAttribute() 0 3 1
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 8
    public function CustomerSystems()
21
    {
22 8
        return $this->hasMany('App\CustomerSystems', 'cust_id', 'cust_id');
23
    }
24
25 8
    public function ParentSystems()
26
    {
27 8
        return $this->hasMany('App\CustomerSystems', 'cust_id', 'parent_id');
28
    }
29
30
    public function ParentCustomer()
31
    {
32
        return $this->hasOne('App\Customers', 'cust_id', 'parent_id');
33
    }
34
35 2
    public function getChildCountAttribute()
36
    {
37 2
        return Customers::where('parent_id', $this->cust_id)->count();
38
    }
39
}
40