|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\OrderStatus; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Contracts\Issuerable; |
|
6
|
|
|
use App\Models\Order; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @property int $order_id Foreign key of \App\Models\Order. |
|
12
|
|
|
* @property-read \App\Models\Order $order |
|
13
|
|
|
* @property string $issuerable_type |
|
14
|
|
|
* @property int $issuerable_id |
|
15
|
|
|
* @property-read \App\Models\Contracts\Issuerable $issuerable |
|
16
|
|
|
* |
|
17
|
|
|
* @see \App\Models\OrderStatus |
|
18
|
|
|
*/ |
|
19
|
|
|
trait Relation |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Define an inverse one-to-one or many relationship with \App\Models\Order. |
|
23
|
|
|
* |
|
24
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
25
|
|
|
*/ |
|
26
|
|
|
public function order(): BelongsTo |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->belongsTo(Order::class); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Return \App\Models\Order model relation value. |
|
33
|
|
|
* |
|
34
|
|
|
* @return \App\Models\Order |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getOrderRelationValue(): Order |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->getRelationValue('order'); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Set \App\Models\Order model relation value. |
|
43
|
|
|
* |
|
44
|
|
|
* @param \App\Models\Order $order |
|
45
|
|
|
* @return $this |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setOrderRelationValue(Order $order) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->order()->associate($order); |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Define a polymorphic, inverse one-to-one or many relationship. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
|
58
|
|
|
* |
|
59
|
|
|
* @see \App\Models\Customer |
|
60
|
|
|
* @see \App\Models\User |
|
61
|
|
|
*/ |
|
62
|
|
|
public function issuerable(): MorphTo |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->morphTo(); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Return \App\Models\Issuerable model relation value. |
|
69
|
|
|
* |
|
70
|
|
|
* @return \App\Models\Contracts\Issuerable |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getIssuerableRelationValue(): Issuerable |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getRelationValue('issuerable'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set \App\Models\Issuerable model relation value. |
|
79
|
|
|
* |
|
80
|
|
|
* @param \App\Models\Contracts\Issuerable $issuerable |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setIssuerableRelationValue(Issuerable $issuerable) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->issuerable()->associate($issuerable); |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|