File tree 2 files changed +20
-10
lines changed 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Whitecube \LaravelPrices \Enums ;
4
+
5
+ enum PriceStatus
6
+ {
7
+ case SCHEDULED ;
8
+ case CURRENT ;
9
+ case EXPIRED ;
10
+ }
Original file line number Diff line number Diff line change 7
7
use Illuminate \Database \Eloquent \Model ;
8
8
use Whitecube \Price \Price as PriceObject ;
9
9
use Whitecube \LaravelPrices \Concerns \HasUuid ;
10
- use Whitecube \LaravelPrices \Exceptions \ PriceValueNotDefinedException ;
10
+ use Whitecube \LaravelPrices \Enums \ PriceStatus ;
11
11
12
12
class Price extends Model
13
13
{
14
14
use HasUuid;
15
15
16
- public $ timestamps = ['activated_at ' ];
17
-
18
16
protected $ guarded = [];
19
17
20
18
protected $ casts = [
21
- 'amount ' => 'integer '
19
+ 'amount ' => 'integer ' ,
20
+ 'activated_at ' => 'datetime ' ,
22
21
];
23
22
24
23
public function __construct (
@@ -80,17 +79,18 @@ public function toObject(): PriceObject
80
79
return PriceObject::ofMinor ($ this ->amount , $ this ->currency );
81
80
}
82
81
83
- public function getStatusAttribute ()
82
+ public function getStatusAttribute (): PriceStatus
84
83
{
85
84
if ($ this ->activated_at > now ()) {
86
- return ' programmed ' ;
85
+ return PriceStatus:: SCHEDULED ;
87
86
}
88
87
89
- $ current = $ this ->priceable ->price ()->first ();
90
- if ($ current ->id == $ this ->id ) {
91
- return 'current ' ;
88
+ $ current = $ this ->priceable ->price ()->current ()->first ();
89
+
90
+ if ($ current ->id == $ this ->id ) {
91
+ return PriceStatus::CURRENT ;
92
92
}
93
93
94
- return ' passed ' ;
94
+ return PriceStatus:: EXPIRED ;
95
95
}
96
96
}
You can’t perform that action at this time.
0 commit comments