get item by sku in api

This commit is contained in:
denisdulici
2017-10-08 23:25:44 +03:00
parent 1a53c60082
commit 033674666f
4 changed files with 12 additions and 5 deletions

View File

@ -27,11 +27,18 @@ class Items extends ApiController
/**
* Display the specified resource.
*
* @param Item $item
* @param int|string $id
* @return \Dingo\Api\Http\Response
*/
public function show(Item $item)
public function show($id)
{
// Check if we're querying by id or sku
if (is_numeric($id)) {
$item = Item::with(['category', 'tax'])->find($id);
} else {
$item = Item::with(['category', 'tax'])->where('sku', $id)->first();
}
return $this->response->item($item, new Transformer());
}