From 6cba265a548228dbb29bd8b52d30513e59f71589 Mon Sep 17 00:00:00 2001 From: Mateusz Qunabu <mateusz@qunabu.com> Date: Thu, 20 Jan 2022 17:16:29 +0100 Subject: [PATCH] Update ContentIndexResource.php (#64) * Update ContentIndexResource.php * Update ContentIndexResource.php * Update LibraryResource.php --- src/Http/Resources/ContentIndexResource.php | 16 ++++++++++++++++ src/Http/Resources/LibraryResource.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Http/Resources/ContentIndexResource.php b/src/Http/Resources/ContentIndexResource.php index 1134382d..d2cb7775 100644 --- a/src/Http/Resources/ContentIndexResource.php +++ b/src/Http/Resources/ContentIndexResource.php @@ -3,15 +3,31 @@ namespace EscolaLms\HeadlessH5P\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; +use EscolaLms\HeadlessH5P\Models\H5PLibrary; +use EscolaLms\HeadlessH5P\Http\Resources\LibraryResource; class ContentIndexResource extends JsonResource { public function toArray($request): array { + $lib = H5PLibrary::find($this->library_id); + return [ 'id' => $this->id, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + 'user_id' => $this->user_id, 'title' => $this->title, 'library_id' => $this->library_id, + 'library' => isset($lib) ? (new LibraryResource($lib))->toArray() : null, + 'parameters' => $this->parameters, + 'params' => $this->params, + 'metadata' => $this->metadata, + 'slug' => $this->slug, + 'filtered' => $this->filtered, + 'disable' => $this->disable, + 'embed_type' => $this->embed_type, + 'nonce' => $this->nonce, ]; } } diff --git a/src/Http/Resources/LibraryResource.php b/src/Http/Resources/LibraryResource.php index f3a282d6..b485a730 100644 --- a/src/Http/Resources/LibraryResource.php +++ b/src/Http/Resources/LibraryResource.php @@ -12,7 +12,7 @@ public function __construct(H5PLibrary $library) $this->resource = $library; } - public function toArray($request): array + public function toArray($request = null): array { return [ 'id' => $this->id,