return 204 response if search has empty result
This commit is contained in:
parent
54565ff4b7
commit
7549f164ae
@ -27,9 +27,16 @@ class ItemController extends Controller
|
||||
*/
|
||||
public function search(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'item' => $this->itemsCollection->findItem($request->input('query')),
|
||||
]);
|
||||
$status = Response::HTTP_NO_CONTENT;
|
||||
$result = $this->itemsCollection->findItem($request->input('query'));
|
||||
$response = [];
|
||||
if ($result->isNotEmpty()) {
|
||||
$status = Response::HTTP_OK;
|
||||
$response = [
|
||||
'items' => $result->toArray(),
|
||||
];
|
||||
}
|
||||
return response()->json($response, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user