Skip to content

Commit dbc441c

Browse files
committed
Add after callbacks to Create endpoint
1 parent 9b64b68 commit dbc441c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Endpoint/Create.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Create implements Endpoint, OpenApiPathsProvider
2727
use ShowsResources;
2828
use HasDescription;
2929

30+
private array $afterCallbacks = [];
31+
3032
public static function make(): static
3133
{
3234
return new static();
@@ -70,11 +72,22 @@ public function handle(Context $context): ?ResponseInterface
7072

7173
$this->saveFields($context, $data);
7274

75+
foreach ($this->afterCallbacks as $callback) {
76+
$callback($model, $context);
77+
}
78+
7379
return json_api_response($document = $this->showResource($context, $model))
7480
->withStatus(201)
7581
->withHeader('Location', $document['data']['links']['self']);
7682
}
7783

84+
public function after(callable $callback): static
85+
{
86+
$this->afterCallbacks[] = $callback;
87+
88+
return $this;
89+
}
90+
7891
private function fillDefaultValues(Context $context, array &$data): void
7992
{
8093
foreach ($context->fields($context->resource) as $field) {

0 commit comments

Comments
 (0)