public function update($id, Request $request) { if ($request->ajax()) { $inputs = Input::all(); $limit = Limit::find($id); if (strlen($inputs['value']) > 0) { $limit->value = str_replace(array(' ', ','), array('', '.'), $inputs['value']); } else { $limit->value = Input::get('value'); } if ($limit->save()) { return response()->json(['status' => 1, 'callback' => 'success', 'message_shot' => 'Успешно!', 'message' => ' Лимит сохранен']); } else { return response()->json(['status' => 0]); } } else { $limit = Limit::find($id); $limit->value = Input::get('limit_value'); $limit->save(); return response()->json($limit); } }
public function update_user(Request $request, $client_id) { $data = $request->all(); if (Gate::denies('manage-user')) { abort(403); } $validator = Validator::make($data, ['name' => 'required|alpha_num_dash_lat|max:255|unique:users,name,' . $client_id, 'email' => 'required|email|max:255|unique:users,email,' . $client_id, 'role' => 'required|in:superadmin,admin,rush,active,suspended', 'expire_time' => 'required|date|after:now', 'limits_rest' => 'required|numeric|min:0', 'limits_min' => 'required|numeric|max:0']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } try { $user = User::where('id', $client_id)->firstOrFail(); } catch (\Exception $e) { \App::abort(404); } $user->name = $data['name']; $user->email = $data['email']; // $user->role = $data['role']; $user->base_role = $data['role']; $limit = $user->limit; if (is_null($limit)) { $limit = new Limit(); $limit->user_id = $user->id; } $limit->limits_rest = $data['limits_rest']; $limit->expire_time = date("Y-m-d H:i:s", strtotime($data['expire_time'])); $limit->expire_limit = $data['limits_min']; if ($user->save() && $limit->save()) { $user->update_status(); $request->session()->flash('success', 'User was successfully updated.'); } else { $request->session()->flash('danger', 'Failed to update User.'); } return redirect()->action('UserController@show_user', ['id' => $user->id]); // return view('show_user', ['client'=>$user,'limit'=>$user->limit]); }