From 5b2b3c72cc0ae980a3e4a474f6b16b9a6d86682a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Preu=C3=9F=20=28envoyr=29?= Date: Wed, 30 Apr 2025 04:23:10 +0200 Subject: [PATCH] add serializable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurice Preuß (envoyr) --- src/Id/Resources/BaseResource.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Id/Resources/BaseResource.php b/src/Id/Resources/BaseResource.php index e28e708..1f0cdfb 100644 --- a/src/Id/Resources/BaseResource.php +++ b/src/Id/Resources/BaseResource.php @@ -4,8 +4,9 @@ namespace Anikeen\Id\Resources; use Anikeen\Id\Concerns\MagicProperties; use Anikeen\Id\Result; +use JsonSerializable; -abstract class BaseResource +abstract class BaseResource implements JsonSerializable { use MagicProperties; @@ -13,4 +14,20 @@ abstract class BaseResource { $this->setMagicProperties($this->result->data); } + + /** + * Returns the collection of resources as an array. + */ + public function toArray(): array + { + return (array)$this->result->data; + } + + /** + * Returns the collection of resources as a JSON string. + */ + public function jsonSerialize(): array + { + return $this->toArray(); + } } \ No newline at end of file