diff --git a/app/Http/Resources/AttributeResource.php b/app/Http/Resources/AttributeResource.php index 2a0267f10e..f93d831f98 100644 --- a/app/Http/Resources/AttributeResource.php +++ b/app/Http/Resources/AttributeResource.php @@ -17,7 +17,7 @@ public function toArray($request) /** @var Attribute $attribute */ $attribute = $this->resource; - return $this->entity([ + return $this->onEntity([ 'name' => $attribute->name, 'value' => $attribute->value, 'parsed' => $attribute->mappedValue(), diff --git a/app/Http/Resources/EntityChild.php b/app/Http/Resources/EntityChild.php index 83980b0475..41caae5809 100644 --- a/app/Http/Resources/EntityChild.php +++ b/app/Http/Resources/EntityChild.php @@ -2,7 +2,9 @@ namespace App\Http\Resources; +use App\Models\Attribute; use App\Models\MiscModel; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Resources\Json\JsonResource; class EntityChild extends JsonResource @@ -34,4 +36,30 @@ public function entity(array $prepared = []) ksort($final); return $final; } + + /** + * Transform the resource into an array. + * + * @return array + */ + public function onEntity(array $prepared = []) + { + /** @var Model|Attribute|mixed $model */ + $model = $this->resource; + $merged = [ + 'id' => $model->id, + + 'is_private' => (bool) $model->is_private, + 'entity_id' => $model->entity_id, + + 'created_at' => $model->created_at, + 'created_by' => $model->created_by, + 'updated_at' => $model->updated_at, + 'updated_by' => $model->updated_by, + ]; + + $final = array_merge($prepared, $merged); + ksort($final); + return $final; + } } diff --git a/app/Http/Resources/EntityEventResource.php b/app/Http/Resources/EntityEventResource.php index 54ccfa49a2..baa12e91c1 100644 --- a/app/Http/Resources/EntityEventResource.php +++ b/app/Http/Resources/EntityEventResource.php @@ -16,7 +16,7 @@ public function toArray($request) { /** @var EntityEvent $model */ $model = $this->resource; - return $this->entity([ + return $this->onEntity([ 'calendar_id' => $model->calendar_id, 'date' => $model->date(), 'day' => $model->day, diff --git a/app/Models/Scopes/SubEntityScopes.php b/app/Models/Scopes/SubEntityScopes.php index 1a2d408040..9118a75331 100644 --- a/app/Models/Scopes/SubEntityScopes.php +++ b/app/Models/Scopes/SubEntityScopes.php @@ -77,7 +77,8 @@ public function scopeWithApi(Builder $query): Builder 'entity', 'entity.tags', 'entity.posts', 'entity.events', 'entity.relationships', 'entity.attributes', 'entity.inventories', - 'entity.assets' + 'entity.assets', + 'entity.abilities', ]; $with = !empty($this->apiWith) ? $this->apiWith : [];