Skip to content

Commit

Permalink
Merge branch 'MG-36' into test-mg-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Jan 22, 2024
2 parents b77c7df + b67443c commit 8039033
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/Http/Controllers/Api/V2/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(private readonly ItemRepository $itemRepository)
{
}

public function show($id)
public function show(string $id)
{
$item = Item::with('images')->findOrFail($id);
return new ItemResource($item);
Expand All @@ -32,4 +32,16 @@ public function suggestions()
->get();
return ItemResource::collection($items);
}

public function related(string $id)
{
$size = request()->get('size', 1);
$item = Item::findOrFail($id);
$related = $item
->related()
->with(['images', 'authorities', 'translations'])
->take($size)
->get();
return ItemResource::collection($related);
}
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@

Route::prefix('v2')->group(function () {
Route::get('items/suggestions', [V2ItemController::class, 'suggestions']);
Route::get('items/{id}/related', [V2ItemController::class, 'related']);
Route::get('items/{id}', [V2ItemController::class, 'show']);
});

0 comments on commit 8039033

Please sign in to comment.