/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { if (!$id) { return Redirect::route('stocks.index')->with('error', 'Please provide Stock id'); } $stock = Stocks::find($id); $product_id = $stock->product_id; if (empty($stock)) { return Redirect::route('stocks.index')->with('error', 'Stock not found'); } $sales = SalesItems::where('stock_id', '=', $id)->count(); if ($sales) { return Redirect::route('stocks.index')->with('error', 'Stock cannot be delete, since this stock already has sale entry'); } Stocks::destroy($id); Products::updateStock($product_id); return Redirect::route('stocks.index')->with('success', 'Stock deleted successfully'); }