Skip to content

Commit

Permalink
Adding taxonomy details to the terms API response
Browse files Browse the repository at this point in the history
  • Loading branch information
NuwanJ committed Nov 30, 2024
1 parent 2f3188b commit 21d91a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/API/TaxonomyApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ public function get_term($term_code)
$result = TaxonomyTerm::where('code', $term_code)->first();

if ($result) {
$data = TaxonomyTermResource::collection([$result])->resolve()[0];
$data['taxonomy'] = $result->taxonomy->code; // Add the taxonomy code at the top-level term

return response()->json(
[
'status' => 'success',
'data' => TaxonomyTermResource::collection([$result])->resolve()[0]
'data' => $data
]
);
} else {
Expand Down
1 change: 0 additions & 1 deletion app/Http/Resources/TaxonomyTermResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function toArray($request)
return [
'code' => $this->code,
'name' => $this->name,
'taxonomy' => $this->taxonomy->code,
'terms' => $this->when(
sizeof($this->children) > 0,
TaxonomyTermResource::collection($this->children)
Expand Down

0 comments on commit 21d91a7

Please sign in to comment.