} else { $json["success"] = false; $json["message"] = "This item (" . $params["sku"] . ") does not exist in our inventory. Use 'new item' mode when checking an item in to register it."; } $response->write(json_encode($json)); return $response->withHeader('Content-type', 'application/json'); }); $app->post('/api/v1/checkout', function ($request, $response, $args) use($app) { $params = $request->getParsedBody(); $json = ["success" => false, "message" => "There was an issue checking out the item (" . $params["sku"] . "). Please contact the tech team!"]; if (!array_key_exists('identity', $params) || Identity::where('name', $params["identity"])->count() < 1) { $json["message"] = "You are not authorized to use the inventory system! Contact your supervisor for access."; $response->write(json_encode($json)); return $response->withHeader('Content-type', 'application/json'); } $item = InventoryItem::where('sku', $params["sku"])->first(); if ($item && $item->available > 0) { $item->checkoutTo($params["identity"]); $json["success"] = true; $json["message"] = "The item (" . $params["sku"] . ") has been checked out to " . $params["identity"] . " successfully!"; } elseif ($item) { $guardians = $item->currentGuardians(); $names = []; foreach ($guardians as $guardian) { $names[$guardian->name] = $guardian->checkout_date; } $json["message"] = "This item (" . $params["sku"] . ") was not checked back in properly. The following people must check this item back in: " . implode(", ", array_keys($names)); } else { $json["message"] = "This item (" . $params["sku"] . ") does not exist in our inventory. Use 'new item' mode when checking an item in to register it."; } $response->write(json_encode($json));