id); return view('misc.show', compact(['misc_data'])); } public function store(Request $request) { $request->validate([ 'name' => 'required|string|min:3', 'price' => 'required|numeric', 'payment_term' => 'required|integer', 'currency' => 'required|string|size:3', 'owned_since' => 'sometimes|nullable|date', 'next_due_date' => 'required|date' ]); $misc_id = Str::random(8); $pricing = new Pricing(); $pricing->insertPricing(5, $misc_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date); Misc::create([ 'id' => $misc_id, 'name' => $request->name, 'owned_since' => $request->owned_since ]); Cache::forget("all_misc"); Home::homePageCacheForget(); return redirect()->route('misc.index') ->with('success', 'Misc service created Successfully.'); } public function edit(Misc $misc) { $misc_data = Misc::misc($misc->id); return view('misc.edit', compact('misc_data')); } public function update(Request $request, Misc $misc) { $request->validate([ 'name' => 'required|string|min:3', 'price' => 'required|numeric', 'payment_term' => 'required|integer', 'currency' => 'required|string|size:3', 'owned_since' => 'sometimes|nullable|date', 'next_due_date' => 'required|date' ]); $misc->update([ 'name' => $request->name, 'owned_since' => $request->owned_since, 'active' => (isset($request->is_active)) ? 1 : 0 ]); $pricing = new Pricing(); $as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Cache::forget("all_misc"); Cache::forget("misc.{$misc->id}"); Home::homePageCacheForget(); return redirect()->route('misc.index') ->with('success', 'Misc service updated Successfully.'); } public function destroy(Misc $misc) { $items = Misc::find($misc->id); $items->delete(); $p = new Pricing(); $p->deletePricing($misc->id); Cache::forget("all_misc"); Cache::forget("misc.{$misc->id}"); Home::homePageCacheForget(); return redirect()->route('misc.index') ->with('success', 'Misc service was deleted Successfully.'); } }