/** * Updates an inventory stock record. * * @param Request $request * @param int|string $inventoryId * @param int|string $stockId * * @return bool|InventoryStock */ public function update(Request $request, $inventoryId, $stockId) { $item = $this->inventory->model()->findOrFail($inventoryId); $stock = $item->stocks()->findOrFail($stockId); $stock->location_id = $request->input('location_id', $stock->location_id); $stock->quantity = $request->input('quantity', $stock->quantity); $stock->reason = $request->input('reason'); $stock->cost = $request->input('cost', 0); if ($stock->save()) { return $stock; } return false; }
/** * Removes the specified inventory. * * @param int|string $id * * @return \Illuminate\Http\JsonResponse|mixed */ public function destroy($id) { $item = $this->inventory->model()->findOrFail($id); if ($item->delete()) { $message = 'Successfully deleted inventory item.'; return redirect()->route('maintenance.inventory.index')->withSuccess($message); } else { $message = 'There was an issue deleting this inventory item. Please try again.'; return redirect()->route('maintenance.inventory.show', [$id])->withSuccess($message); } }