Skip to content

Commit 869026f

Browse files
committed
Revert "feat!: don't refresh the model after create/update"
Turns out this is important - because scopes need to be run on the model before it is shown. This reverts commit da69f8f.
1 parent da69f8f commit 869026f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Endpoint/Concerns/SavesData.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,14 @@ private function runSavedCallbacks(ResourceType $resourceType, array $data, $mod
308308
);
309309
}
310310
}
311+
312+
/**
313+
* Get a fresh copy of the model for display.
314+
*/
315+
private function freshModel(ResourceType $resourceType, $model, Context $context)
316+
{
317+
$id = $resourceType->getAdapter()->getId($model);
318+
319+
return $this->findResource($resourceType, $id, $context);
320+
}
311321
}

src/Endpoint/Create.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function handle(Context $context, ResourceType $resourceType): ResponseIn
5656

5757
run_callbacks($schema->getListeners('created'), [&$model, $context]);
5858

59+
$model = $this->freshModel($resourceType, $model, $context);
60+
5961
return (new Show())
6062
->handle($context, $resourceType, $model)
6163
->withStatus(201)

src/Endpoint/Update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function handle(Context $context, ResourceType $resourceType, $model): Re
5353

5454
run_callbacks($schema->getListeners('updated'), [&$model, $context]);
5555

56+
$model = $this->freshModel($resourceType, $model, $context);
57+
5658
return (new Show())
5759
->handle($context, $resourceType, $model);
5860
}

0 commit comments

Comments
 (0)