public function store(Request $request) { $filtered=Expense::where('category',$request->category)->onlyTrashed()->first(); if($filtered!==null) { expense::withTrashed()->where('id', $filtered['id'])->restore(); return redirect()->route('expense.index')->with('success', "Expense category restored successfully"); } else{ try { $validated = $request->validate([ 'category' => 'required|alpha|unique:expense_categories', ], [ 'category.unique' => 'This category is already exist' ] ); $expense = new Expense; $expense->category = $validated['category']; $expense->save(); return redirect()->route('expense.index')->with('success', "Expense category added successfully"); } catch (\Exception $e) { report($e); return redirect()->back()->with('error', 'Failed to edit the category! Please try again.'); } } }
try { // code that can throw exceptions } catch(Exception $e) { // code that runs when an exception is caught } finally { // code that always runs regardless of whether an exception was caught }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)