|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
8
|
|
|
|
|
9
|
|
|
class Customer extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
use HasFactory; |
|
12
|
|
|
use SoftDeletes; |
|
13
|
|
|
|
|
14
|
|
|
protected $primaryKey = 'cust_id'; |
|
15
|
|
|
protected $guarded = ['updated_at', 'created_at', 'deleted_at']; |
|
16
|
|
|
protected $hidden = ['updated_at', 'created_at', 'deleted_at']; |
|
17
|
|
|
|
|
18
|
|
|
public function EquipmentType() |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->hasManyThrough('App\Models\EquipmentType', 'App\Models\CustomerEquipment', 'cust_id', 'equip_id', 'cust_id', 'equip_id'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
// TODO - ParentEquipmentType() |
|
24
|
|
|
|
|
25
|
|
|
public function ParentEquipment() |
|
26
|
|
|
{ |
|
27
|
|
|
// TODO - verify only shared equipment make it through |
|
28
|
|
|
return $this->hasMany(CustomerEquipment::class, 'cust_id', 'parent_id')->where('shared', true); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function CustomerEquipment() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->hasMany(CustomerEquipment::class, 'cust_id', 'cust_id'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function Parent() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->belongsTo(Customer::class, 'parent_id', 'cust_id'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function CustomerContact() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->hasMany(CustomerContact::class, 'cust_id', 'cust_id'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function ParentContact() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->hasMany(CustomerContact::class, 'cust_id', 'parent_id')->where('shared', true); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function CustomerNote() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->hasMany(CustomerNote::class, 'cust_id', 'cust_id'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|