public function update($id)
 {
     $data = Input::all();
     $avatar = Input::file('avatar');
     if (FEUsersHelper::isCurrentUser($id)) {
         $validator = FEUsersHelper::validateUpdateInfo();
         if ($validator->fails()) {
             $messages = $validator->messages();
             $errors = json_encode($messages);
             echo $errors;
         } else {
             $user = Users::where('account', $data['account'])->first();
             $user['fullname'] = $data['fullname'];
             $user['email'] = $data['email'];
             $user['phone'] = $data['phone'];
             $user['address'] = $data['address'];
             $user['about'] = $data['about'];
             if ($avatar) {
                 $upload_avatar_folder = 'avatar/' . $user->account . "/";
                 $name = $avatar->getFilename() . uniqid() . "." . $avatar->getClientOriginalExtension();
                 $avatar->move(public_path() . "/" . $upload_avatar_folder, $name);
                 $user->avatar = 'public/' . $upload_avatar_folder . $name;
             }
             $user->save();
             Session::flush('user');
             Session::put('user', $user);
             echo json_encode('success');
         }
     } else {
         echo json_encode('fail');
     }
     //        return false;
 }
Example #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!FEUsersHelper::validateUpdateInfo()) {
         Session::flash('update_status', false);
         return Redirect::to('user/' . Session::get('current_user') . '/edit');
     } else {
         if (!FEUsersHelper::isExistedEmail()) {
             $user = FEUsersHelper::updateUser($id);
             if ($user) {
                 Session::flash('update_status', true);
                 Session::set("current_user", $user->id);
             }
         }
         return Redirect::to('user/' . Session::get('current_user') . '/edit');
     }
 }