Profile-update-code-rework

https://github.com/ladybirdweb/faveo-helpdesk/issues/257 solved
This commit is contained in:
Manish Verma
2016-10-20 13:38:01 +05:30
parent 024146d38e
commit 03ff310d1e
2 changed files with 34 additions and 48 deletions

View File

@@ -191,7 +191,7 @@ class GroupController extends Controller
if ($users) {
$user = '<li>'.Lang::get('lang.there_are_agents_assigned_to_this_group_please_unassign_them_from_this_group_to_delete').'</li>';
return redirect('groups')->with('fails', Lang('lang.group_cannot_delete').$user);
return redirect('groups')->with('fails', Lang::get('lang.group_cannot_delete').$user);
}
$group_assign_department->where('group_id', $id)->delete();
$groups = $group->whereId($id)->first();

View File

@@ -668,23 +668,21 @@ class UserController extends Controller
*/
public function postProfileedit(ProfileRequest $request)
{
try {
// geet authenticated user details
$user = Auth::user();
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
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(['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();
// checking availability of agent profile ppicture
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;
}
}
// checking if the post system includes agent profile picture upload
if (Input::file('profile_pic')) {
// fetching picture name
$name = Input::file('profile_pic')->getClientOriginalName();
@@ -696,32 +694,20 @@ class UserController extends Controller
Input::file('profile_pic')->move($destinationPath, $fileName);
// saving filename to database
$user->profile_pic = $fileName;
} else {
try {
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
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(['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', 'gender', 'mobile'))->save();
if ($request->get('mobile')) {
$user->mobile = $request->get('mobile');
} else {
$user->mobile = null;
}
$user->save();
if ($user->save()) {
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
} else {
return Redirect::route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully'));
}
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
} catch (Exception $e) {
return Redirect::route('profile')->with('success', $e->getMessage());
}
}
if ($user->fill($request->except('profile_pic'))->save()) {
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
return Redirect::route('profile')->with('fails', $e->getMessage());
}
}