/** * Update the specified resource in storage. * * @param int $id */ public function update($id, Request $request) { $this->validate($request, ['title' => 'required', 'short' => 'required', 'status' => 'required', 'rpc_host' => 'required', 'rpc_port' => 'required', 'rpc_username' => 'required', 'rpc_password' => 'required']); $wallet = Wallet::findOrFail($id); $wallet->update($request->all()); Session::flash('flash_message', 'Wallet updated!'); return redirect('admin/wallets'); }
public function edit(Request $request) { $id = 0; if (isset($request->id)) { $id = $request->id; } $modelData = new \stdClass(); if ($id > 0) { try { $modelData = Wallet::findOrFail($id); } catch (ModelNotFoundException $e) { session()->flash('message', trans('admin_common.Invalid Wallet Item')); return redirect(url('admin/wallet')); } } /** * form is submitted check values and save if needed */ if ($request->isMethod('post')) { /** * validate data */ $rules = ['user_id' => 'required|integer|not_in:0', 'ad_id' => 'integer|not_in:0', 'sum' => 'required|numeric|not_in:0', 'wallet_date' => 'required|max:255', 'wallet_description' => 'required|max:255']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { $this->throwValidationException($request, $validator); } /** * get data from form */ $data = $request->all(); if (empty($data['ad_id'])) { unset($data['ad_id']); } /** * save or update */ if (!isset($modelData->wallet_id)) { Wallet::create($data); } else { $modelData->update($data); } /** * clear cache, set message, redirect to list */ Cache::flush(); session()->flash('message', trans('admin_common.Wallet Item saved')); return redirect(url('admin/wallet')); } return view('admin.wallet.wallet_edit', ['modelData' => $modelData]); }