diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 3de27ee..099e9f2 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -39,6 +39,7 @@ module.exports = { collapsable: false, children: [ 'list', + 'show', 'create', 'update', 'delete', diff --git a/docs/create.md b/docs/create.md index ec180ad..49fdf35 100644 --- a/docs/create.md +++ b/docs/create.md @@ -29,7 +29,7 @@ $type->newModel(function (Context $context) { Run before the model is saved. ```php -$type->onCreating(function ($model, Context $context) { +$type->onCreating(function (&$model, Context $context) { // do something }); ``` @@ -39,7 +39,7 @@ $type->onCreating(function ($model, Context $context) { Run after the model is saved. ```php -$type->onCreated(function ($model, Context $context) { +$type->onCreated(function (&$model, Context $context) { $context->meta('foo', 'bar'); }); ``` diff --git a/docs/delete.md b/docs/delete.md index 887fade..0727c14 100644 --- a/docs/delete.md +++ b/docs/delete.md @@ -19,7 +19,7 @@ $type->deletable(function (Context $context) { Run before the model is deleted. ```php -$type->onDeleting(function ($model, Context $context) { +$type->onDeleting(function (&$model, Context $context) { // do something }); ``` @@ -29,7 +29,7 @@ $type->onDeleting(function ($model, Context $context) { Run after the model is deleted. ```php -$type->onDeleted(function ($model, Context $context) { +$type->onDeleted(function (&$model, Context $context) { // do something }); ``` diff --git a/docs/show.md b/docs/show.md new file mode 100644 index 0000000..ce30121 --- /dev/null +++ b/docs/show.md @@ -0,0 +1,15 @@ +# Showing Resources + +For each resource type, a `GET /{type}/{id}` endpoint is exposed to show an individual resource. + +## Events + +### `onShow` + +Run after models and relationships have been retrieved, but before they are serialized into a JSON:API document. + +```php +$type->onShow(function (&$model, Context $context) { + // do something +}); +``` diff --git a/docs/update.md b/docs/update.md index 89fdb9e..21ca96c 100644 --- a/docs/update.md +++ b/docs/update.md @@ -19,7 +19,7 @@ $type->updatable(function (Context $context) { Run before the model is saved. ```php -$type->onUpdating(function ($model, Context $context) { +$type->onUpdating(function (&$model, Context $context) { // do something }); ``` @@ -29,7 +29,7 @@ $type->onUpdating(function ($model, Context $context) { Run after the model is saved. ```php -$type->onUpdated(function ($model, Context $context) { +$type->onUpdated(function (&$model, Context $context) { // do something }); ``` diff --git a/src/Endpoint/Create.php b/src/Endpoint/Create.php index dd238dd..3f7603c 100644 --- a/src/Endpoint/Create.php +++ b/src/Endpoint/Create.php @@ -54,11 +54,11 @@ class Create $this->assertDataValid($data, $model, $context, true); $this->setValues($data, $model, $context); - run_callbacks($schema->getListeners('creating'), [$model, $context]); + run_callbacks($schema->getListeners('creating'), [&$model, $context]); $this->save($data, $model, $context); - run_callbacks($schema->getListeners('created'), [$model, $context]); + run_callbacks($schema->getListeners('created'), [&$model, $context]); return (new Show($this->api, $this->resource, $model)) ->handle($context) diff --git a/src/Endpoint/Delete.php b/src/Endpoint/Delete.php index 5f5ba7c..3dfdd8a 100644 --- a/src/Endpoint/Delete.php +++ b/src/Endpoint/Delete.php @@ -44,7 +44,7 @@ class Delete throw new ForbiddenException; } - run_callbacks($schema->getListeners('deleting'), [$this->model, $context]); + run_callbacks($schema->getListeners('deleting'), [&$this->model, $context]); if ($deleteCallback = $schema->getDeleteCallback()) { $deleteCallback($this->model, $context); @@ -52,7 +52,7 @@ class Delete $this->resource->getAdapter()->delete($this->model); } - run_callbacks($schema->getListeners('deleted'), [$this->model, $context]); + run_callbacks($schema->getListeners('deleted'), [&$this->model, $context]); return new Response(204); } diff --git a/src/Endpoint/Show.php b/src/Endpoint/Show.php index f65dc39..f50b9e3 100644 --- a/src/Endpoint/Show.php +++ b/src/Endpoint/Show.php @@ -42,7 +42,7 @@ class Show $this->loadRelationships([$this->model], $include, $context); - run_callbacks($this->resource->getSchema()->getListeners('show'), [$this->model, $context]); + run_callbacks($this->resource->getSchema()->getListeners('show'), [&$this->model, $context]); $serializer = new Serializer($this->api, $context); $serializer->add($this->resource, $this->model, $include); diff --git a/src/Endpoint/Update.php b/src/Endpoint/Update.php index 674e754..88ca145 100644 --- a/src/Endpoint/Update.php +++ b/src/Endpoint/Update.php @@ -52,11 +52,11 @@ class Update $this->assertDataValid($data, $this->model, $context, false); $this->setValues($data, $this->model, $context); - run_callbacks($schema->getListeners('updating'), [$this->model, $context]); + run_callbacks($schema->getListeners('updating'), [&$this->model, $context]); $this->save($data, $this->model, $context); - run_callbacks($schema->getListeners('updated'), [$this->model, $context]); + run_callbacks($schema->getListeners('updated'), [&$this->model, $context]); return (new Show($this->api, $this->resource, $this->model)) ->handle($context);