44
55use Devsrv \ScheduledAction \Enums \Status ;
66use Illuminate \Database \Eloquent \Model ;
7- use DateTime ;
7+ use Carbon \ Carbon ;
88use InvalidArgumentException ;
99
10-
1110trait FluentCreate
1211{
1312 private static $ forModel ;
14- private static $ actAt ;
15- private static $ actBy ;
13+ private static $ actDate = null ;
14+ private static $ actTime ;
15+ private static $ actWith ;
1616 private static $ actionStatus = null ;
1717 private static $ props = [];
1818
@@ -21,13 +21,24 @@ public static function forModel(Model $model) {
2121 return new self ;
2222 }
2323
24- public static function actAt (DateTime $ at ) {
25- self ::$ actAt = $ at ;
24+ public static function actAt (Carbon $ carbon ) {
25+ self ::$ actDate = $ carbon ;
26+ self ::$ actTime = $ carbon ;
27+ return new self ;
28+ }
29+
30+ public static function actDate (Carbon $ carbon ) {
31+ self ::$ actDate = $ carbon ;
32+ return new self ;
33+ }
34+
35+ public static function actTime (Carbon $ carbon ) {
36+ self ::$ actTime = $ carbon ;
2637 return new self ;
2738 }
2839
29- public static function actBy (string $ by ) {
30- self ::$ actBy = $ by ;
40+ public static function actWith (string $ by ) {
41+ self ::$ actWith = $ by ;
3142 return new self ;
3243 }
3344
@@ -60,14 +71,15 @@ public function createSchedule() {
6071 $ this ->create ([
6172 'actionable_type ' => get_class (self ::$ forModel ),
6273 'actionable_id ' => (self ::$ forModel )->getKey (),
63- 'action ' => self ::$ actBy ,
74+ 'action ' => self ::$ actWith ,
6475 'properties ' => self ::$ props ,
6576 'status ' => self ::$ actionStatus ?? Status::PENDING ,
66- 'act_at ' => self ::$ actAt ,
77+ 'act_on ' => self ::$ actDate ? self ::$ actDate ->toDateString () : null ,
78+ 'act_at ' => self ::$ actTime ->toTimeString (),
6779 ]);
6880 }
6981
7082 private function beforeCreate () {
71- throw_if (! isset (self ::$ forModel , self ::$ actBy , self ::$ actAt ), new InvalidArgumentException ('model attribute missing ' ));
83+ throw_if (! isset (self ::$ forModel , self ::$ actWith , self ::$ actTime ), new InvalidArgumentException ('model attribute missing ' ));
7284 }
7385}
0 commit comments