Skip to content

Commit 7f3cbd5

Browse files
committed
Self link may not always be present
1 parent da833c0 commit 7f3cbd5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Endpoint/Create.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ public function handle(Context $context): ?ResponseInterface
7676
$callback($model, $context);
7777
}
7878

79-
return json_api_response($document = $this->showResource($context, $model))
80-
->withStatus(201)
81-
->withHeader('Location', $document['data']['links']['self']);
79+
$response = json_api_response(
80+
$document = $this->showResource($context, $model),
81+
)->withStatus(201);
82+
83+
if ($location = $document['data']['links']['self'] ?? null) {
84+
$response = $response->withHeader('Location', $location);
85+
}
86+
87+
return $response;
8288
}
8389

8490
public function after(callable $callback): static

0 commit comments

Comments
 (0)