Esempio n. 1
0
 public function update($id)
 {
     $user = User::findOrFail($id);
     $this->authorOrAdminPermissioinRequire($user->id);
     $data = Input::only('first_name', 'last_name', 'fullname', 'city', 'company', 'twitter_account', 'personal_website', 'signature', 'introduction', 'image_url');
     $data['fullname'] = trim(Input::get('first_name')) . '.' . trim(Input::get('last_name'));
     if (Input::hasFile('image_url')) {
         if ($user['image_url'] == '') {
             App::make('Phphub\\Forms\\UserUpdateForm')->validate($data);
             $fileName = $data['image_url']->getClientOriginalName();
             $path = user_photos_path();
             $image = Image::make($data['image_url']->getRealPath());
             File::exists($path) or File::makeDirectory($path);
             $image->resize(180, 180)->save($path . '180-' . $fileName);
             $data['image_url'] = '180-' . $fileName;
             $path = user_photos_path();
             $user->update($data);
             Flash::success(lang('Operation succeeded.'));
             return Redirect::route('users.show', $id);
         } else {
             //means there was an image, update and delete the old image
             App::make('Phphub\\Forms\\UserUpdateForm')->validate($data);
             $filename = $user['image_url'];
             $fileName = $data['image_url']->getClientOriginalName();
             $path = user_photos_path();
             $image = Image::make($data['image_url']->getRealPath());
             File::exists($path) or File::makeDirectory($path);
             $image->resize(180, 180)->save($path . '180-' . $fileName);
             $data['image_url'] = '180-' . $fileName;
             $path = user_photos_path();
             File::delete($path . $filename);
             $user->update($data);
             Flash::success(lang('Operation succeeded.'));
             return Redirect::route('users.show', $id);
         }
     } else {
         $data['image_url'] = $user['image_url'];
         $user->update($data);
         Flash::success(lang('Operation succeeded.'));
         return Redirect::route('users.show', $id);
     }
 }
Esempio n. 2
0
 public function updateProfile()
 {
     $user = \Auth::user();
     if ($user == null) {
         return redirect('home');
     }
     $input = Request::all();
     // Validation
     $v = Validator::make($input, ['first_name' => 'max:50', 'last_name' => 'max:50', 'name' => 'required|max:50|alpha_dash|unique:users,name,' . $user['id'], 'birthday' => 'required|date_format:Y-m-d', 'country' => 'max:50', 'city' => 'max:50', 'occupation' => 'max:50', 'skype_id' => 'min:6|max:32|alpha_num|unique:users,skype_id,' . $user['id'], 'btc_address' => 'min:26|max:35|alpha_num|unique:users,btc_address,' . $user['id'], 'profile_photo' => 'image|max:25000']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors());
     }
     $user->update($input);
     if (!empty($input['profile_photo'])) {
         // Save Photos
         $fileName = time() . '_' . $input['profile_photo']->getClientOriginalName();
         $extension = $input['profile_photo']->getClientOriginalExtension();
         $user_id = $user['id'];
         $image = \Image::make(Request::file('profile_photo'));
         $image->backup();
         $imageTypes = array_keys(config('user_image'));
         foreach ($imageTypes as $imageType) {
             $path = user_photos_path($imageType);
             \File::exists($path) or \File::makeDirectory($path, 0775, true);
             if ($imageType == 'original') {
                 $height = $image->height();
                 $width = $image->width();
             } else {
                 $height = config('user_image' . '.' . $imageType)['height'];
                 $width = config('user_image' . '.' . $imageType)['width'];
                 $image->resize($height, $width);
             }
             $image->save($path . $fileName);
             $image->reset();
             // store this path in photos table
             $photo = new \App\Photo();
             $photo['user_id'] = $user_id;
             $photo['type'] = $imageType;
             $photo['name'] = $fileName;
             $photo['height'] = $height;
             $photo['width'] = $width;
             $photo['extension'] = $extension;
             $photo->save();
         }
     }
     \Session::flash("flash_message", "Your profile has been updated !!!");
     return redirect('users');
 }