File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ class Create implements Endpoint, OpenApiPathsProvider
27
27
use ShowsResources;
28
28
use HasDescription;
29
29
30
+ private array $ afterCallbacks = [];
31
+
30
32
public static function make (): static
31
33
{
32
34
return new static ();
@@ -70,11 +72,22 @@ public function handle(Context $context): ?ResponseInterface
70
72
71
73
$ this ->saveFields ($ context , $ data );
72
74
75
+ foreach ($ this ->afterCallbacks as $ callback ) {
76
+ $ callback ($ model , $ context );
77
+ }
78
+
73
79
return json_api_response ($ document = $ this ->showResource ($ context , $ model ))
74
80
->withStatus (201 )
75
81
->withHeader ('Location ' , $ document ['data ' ]['links ' ]['self ' ]);
76
82
}
77
83
84
+ public function after (callable $ callback ): static
85
+ {
86
+ $ this ->afterCallbacks [] = $ callback ;
87
+
88
+ return $ this ;
89
+ }
90
+
78
91
private function fillDefaultValues (Context $ context , array &$ data ): void
79
92
{
80
93
foreach ($ context ->fields ($ context ->resource ) as $ field ) {
You can’t perform that action at this time.
0 commit comments