|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MyriadDataStore\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @property \JsonFieldCast\Json\SimpleJsonField $details |
|
11
|
|
|
* @property \JsonFieldCast\Json\SimpleJsonField $communications |
|
12
|
|
|
*/ |
|
13
|
|
|
class MyriadContact extends Model |
|
14
|
|
|
{ |
|
15
|
|
|
public $incrementing = false; |
|
16
|
|
|
|
|
17
|
|
|
protected $guarded = []; |
|
18
|
|
|
|
|
19
|
|
|
protected $casts = [ |
|
20
|
|
|
'details' => \JsonFieldCast\Casts\SimpleJsonField::class, |
|
21
|
|
|
'communications' => \JsonFieldCast\Casts\SimpleJsonField::class, |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
6 |
|
public function getTable(): string |
|
25
|
|
|
{ |
|
26
|
6 |
|
return config('myriad-data-store.tables.contacts'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getNameAttribute(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return implode(' ', array_filter([ |
|
32
|
|
|
$this->details->getAttribute('Title'), |
|
33
|
|
|
$this->details->getAttribute('Forename'), |
|
34
|
|
|
$this->details->getAttribute('Surname'), |
|
35
|
|
|
])); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function contactType(): BelongsTo |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->belongsTo(MyriadContactType::class, 'contact_type_id', 'id'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function ordersAsDespatch(): HasMany |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->hasMany(MyriadOrder::class, 'despatch_contact_id', 'id'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function ordersAsInvoice(): HasMany |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->hasMany(MyriadOrder::class, 'invoice_contact_id', 'id'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function ordersAsAgent(): HasMany |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->hasMany(MyriadOrder::class, 'agent_contact_id', 'id'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|