From 98a6bd7b427f6a441ce9230c271f8566c2c79694 Mon Sep 17 00:00:00 2001 From: Manish Verma Date: Thu, 20 Oct 2016 18:53:07 +0530 Subject: [PATCH] Profile edit bug fix patch --- .../Admin/helpdesk/AgentController.php | 3 +- .../Agent/helpdesk/UserController.php | 5 +- .../Client/helpdesk/GuestController.php | 69 ++++++++----------- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/Admin/helpdesk/AgentController.php b/app/Http/Controllers/Admin/helpdesk/AgentController.php index 94c9b46f6..2197277df 100644 --- a/app/Http/Controllers/Admin/helpdesk/AgentController.php +++ b/app/Http/Controllers/Admin/helpdesk/AgentController.php @@ -240,7 +240,8 @@ class AgentController extends Controller if ($request->input('country_code') != '' or $request->input('country_code') != null) { $user->country_code = $request->input('country_code'); } - $user->fill($request->except('daylight_save', 'limit_access', 'directory_listing', 'vocation_mode', 'assign_team'))->save(); + $user->mobile = ($request->input('mobile') == '') ? null : $request->input('mobile'); + $user->fill($request->except('daylight_save', 'limit_access', 'directory_listing', 'vocation_mode', 'assign_team', 'mobile')); $user->assign_group = $request->group; $user->primary_dpt = $request->primary_department; $user->agent_tzone = $request->agent_time_zone; diff --git a/app/Http/Controllers/Agent/helpdesk/UserController.php b/app/Http/Controllers/Agent/helpdesk/UserController.php index 02d17baae..362a7ddd1 100644 --- a/app/Http/Controllers/Agent/helpdesk/UserController.php +++ b/app/Http/Controllers/Agent/helpdesk/UserController.php @@ -610,8 +610,9 @@ class UserController extends Controller $users->country_code = $request->country_code; } } - // dd($request->input()); - $users->fill($request->input())->save(); + $users->mobile = ($request->input('mobile') == '') ? null : $request->input('mobile'); + $users->fill($request->except('mobile')); + $users->save(); $orgid = $request->input('org_id'); $this->storeUserOrgRelation($users->id, $orgid); /* redirect to Index page with Success Message */ diff --git a/app/Http/Controllers/Client/helpdesk/GuestController.php b/app/Http/Controllers/Client/helpdesk/GuestController.php index c52e95eb3..ba7b2830f 100644 --- a/app/Http/Controllers/Client/helpdesk/GuestController.php +++ b/app/Http/Controllers/Client/helpdesk/GuestController.php @@ -80,58 +80,43 @@ class GuestController extends Controller */ public function postProfile(ProfileRequest $request) { - $user = User::where('id', '=', Auth::user()->id)->first(); - $user->gender = $request->get('gender'); - $user->save(); - if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') { - if ($request->input('gender') == 1) { - $name = 'avatar5.png'; - $destinationPath = 'uploads/profilepic'; - $user->profile_pic = $name; - } elseif ($request->input('gender') == 0) { - $name = 'avatar2.png'; - $destinationPath = 'uploads/profilepic'; - $user->profile_pic = $name; - } - } - if (Input::file('profile_pic')) { - //$extension = Input::file('profile_pic')->getClientOriginalExtension(); - $name = Input::file('profile_pic')->getClientOriginalName(); - $destinationPath = 'uploads/profilepic'; - $fileName = rand(0000, 9999).'.'.$name; - //echo $fileName; - Input::file('profile_pic')->move($destinationPath, $fileName); - $user->profile_pic = $fileName; - } else { + try { + // geet authenticated user details + $user = Auth::user(); if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) { - return redirect()->back()->with(['fails1' => Lang::get('lang.country-code-required-error'), - 'country_code' => 1, ])->withInput(); + return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput(); } else { $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); if (!count($code)) { - return redirect()->back()->with(['fails1' => Lang::get('lang.incorrect-country-code-error'), - 'country_code' => 1, ])->withInput(); - } else { - $user->country_code = $request->input('country_code'); - } + return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); + } + $user->country_code = $request->country_code; + } + $user->fill($request->except('profile_pic', 'mobile')); + $user->gender = $request->input('gender'); + $user->save(); + if (Input::file('profile_pic')) { + // fetching picture name + $name = Input::file('profile_pic')->getClientOriginalName(); + // fetching upload destination path + $destinationPath = 'uploads/profilepic'; + // adding a random value to profile picture filename + $fileName = rand(0000, 9999).'.'.$name; + // moving the picture to a destination folder + Input::file('profile_pic')->move($destinationPath, $fileName); + // saving filename to database + $user->profile_pic = $fileName; } if ($request->get('mobile')) { - $mobile = $request->get('mobile'); + $user->mobile = $request->get('mobile'); } else { - $mobile = null; + $user->mobile = null; } - $check = $this->checkMobile($mobile); - if ($check == true) { - return redirect()->back()->with(['fails1' => Lang::get('lang.mobile-has-been-taken'), 'country_code' => 1])->withInput(); + if ($user->save()) { + } else { } - $user->fill($request->except('profile_pic', 'gender', 'mobile')); - $user->mobile = $mobile; - $user->save(); - return redirect()->back()->with('success1', Lang::get('lang.profile_updated_sucessfully')); - } - if ($user->fill($request->except('profile_pic'))->save()) { - return redirect()->back()->with('success1', Lang::get('lang.profile_updated_sucessfully')); + } catch (Exception $e) { } }