本文整理汇总了PHP中App\Http\Requests\UserRequest::file方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRequest::file方法的具体用法?PHP UserRequest::file怎么用?PHP UserRequest::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Requests\UserRequest
的用法示例。
在下文中一共展示了UserRequest::file方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param User $user
* @return \Illuminate\Http\Response
*/
public function update(UserRequest $request, User $user)
{
$user->update($request->only(['name', 'occupation', 'bio', 'email']));
$files_id[] = $request->hasFile('photo') ? $this->uploadFile($user, $request->file('photo'), 'profile_photo') : $request->input('photo_id');
$files_id[] = $request->hasFile('cover') ? $this->uploadFile($user, $request->file('cover'), 'profile_cover') : $request->input('cover_id');
$user->files()->sync($files_id);
session()->flash('flash_message', 'Se han actualizado los datos de perfil');
return redirect('admin/settings?tab=profile');
}
示例2: postUpdate
/**
* Update profile
*
* @return Response
*/
public function postUpdate(\App\Http\Requests\UserRequest $request)
{
$user_id = $this->auth->user()->id;
$this->user->updateProfile($user_id, $request->all());
if ($request->hasFile('avatar')) {
$this->user->updateAvatar($user_id, $request->file('avatar'));
}
if ($request->hasFile('cover')) {
$this->user->updateCover($user_id, $request->file('cover'));
}
return redirect()->action('UserController@getUpdate')->with('flash_message', trans('user.update_success'));
}
示例3: update
public function update(Requests\UserRequest $request)
{
$user = auth()->user();
$oldAvatarName = $user->avatar;
$avatarName = $user->id . '.' . $request->file('avatar')->getClientOriginalExtension();
$user->avatar = $avatarName;
$user->save();
$uploadPath = base_path() . '/public/uploads/users/avatars/' . $user->id . '/';
if ($oldAvatarName) {
$oldAvatarFile = $uploadPath . $oldAvatarName;
if (file_exists($oldAvatarFile)) {
unlink(realpath($oldAvatarFile));
}
}
$request->file('avatar')->move($uploadPath, $avatarName);
return redirect('/')->with('flash_success', 'Avatar success updated.');
}
示例4: atualiza
public function atualiza(UserRequest $request)
{
$id = Auth::user()->id;
$user = User::find($id);
$user->name = $request->nome;
// Verifica se usuário deseja alterar a foto
if ($request->hasFile('foto')) {
$user->photo = '/' . $request->file('foto')->move('img/uploads/users');
}
// Verifica a senha antiga
if (Hash::check($request->senhaAntiga, Auth::user()->password)) {
$user->password = Hash::make($request->senhaNova);
$user->save();
Auth::logout();
return redirect()->action('HomeController@index');
}
$user->save();
return redirect()->action('UserController@edita');
}
示例5: postUpdate
public function postUpdate(UserRequest $request)
{
$user = $this->user->findById(Auth::user()->id);
$user->name = $request->input('name');
$user->fio = $request->input('fio');
$user->phone_number = $request->input('phone');
$user->address = $request->input('address');
$user->birth = $request->input('birth');
$user->get_news = $request->input('get_news');
$user->email = $request->input('email');
if ($request->hasFile('photo')) {
try {
$image = Image::make($request->file('photo'));
// check the directories
if (!File::exists($this->saveImgDir)) {
File::makeDirectory($this->saveImgDir);
}
if (!File::exists($this->saveImgDir . '/avatars')) {
File::makeDirectory($this->saveImgDir . '/avatars');
}
if (!File::exists($this->saveImgDir . '/avatars/' . $user->id)) {
File::makeDirectory($this->saveImgDir . '/avatars/' . $user->id);
}
// dir to save image
$dir = $this->saveImgDir . '/avatars/' . $user->id;
if (!File::exists($dir)) {
File::makeDirectory($dir);
}
// save medium
$image->fit(240, 240)->save($dir . '/avatar.jpg');
$user->photo = $dir . '/avatar.jpg';
} catch (Exception $e) {
dd($e);
}
} else {
dd(56);
}
$user->save();
return view('user.profile')->withUser($user);
}
示例6: storeImage
/**
* Save image to uploads folder and change the name to something unique
*
* @param UserRequest $request
* @param $field
* @return array
*/
private function storeImage(UserRequest $request, $field)
{
$data = $request->except([$field]);
if ($request->file($field)) {
$file = $request->file($field);
$request->file($field);
$fileName = rename_file($file->getClientOriginalName(), $file->getClientOriginalExtension());
$path = '/uploads/' . str_plural($field);
$move_path = public_path() . $path;
$file->move($move_path, $fileName);
$data[$field] = $path . $fileName;
}
return $data;
}
示例7: update
/**
* User update form processing page.
*
* @param User $user
* @param UserRequest $request
* @return Redirect
*/
public function update(User $user, UserRequest $request)
{
try {
$user->first_name = $request->get('first_name');
$user->last_name = $request->get('last_name');
$user->email = $request->get('email');
$user->dob = $request->get('dob');
$user->bio = $request->get('bio');
$user->gender = $request->get('gender');
$user->country = $request->get('country');
$user->state = $request->get('state');
$user->city = $request->get('city');
$user->address = $request->get('address');
$user->postal = $request->get('postal');
if ($password = $request->has('password')) {
$user->password = Hash::make($password);
}
// is new image uploaded?
if ($file = $request->file('pic')) {
$extension = $file->getClientOriginalExtension() ?: 'png';
$folderName = '/uploads/users/';
$destinationPath = public_path() . $folderName;
$safeName = str_random(10) . '.' . $extension;
$file->move($destinationPath, $safeName);
//delete old pic if exists
if (File::exists(public_path() . $folderName . $user->pic)) {
File::delete(public_path() . $folderName . $user->pic);
}
//save new file path into db
$user->pic = $safeName;
}
//save record
$user->save();
// Get the current user groups
$userRoles = $user->roles()->lists('id')->all();
// Get the selected groups
$selectedRoles = $request->get('groups', array());
// Groups comparison between the groups the user currently
// have and the groups the user wish to have.
$rolesToAdd = array_diff($selectedRoles, $userRoles);
$rolesToRemove = array_diff($userRoles, $selectedRoles);
// Assign the user to groups
foreach ($rolesToAdd as $roleId) {
$role = Sentinel::findRoleById($roleId);
$role->users()->attach($user);
}
// Remove the user from groups
foreach ($rolesToRemove as $roleId) {
$role = Sentinel::findRoleById($roleId);
$role->users()->detach($user);
}
// Activate / De-activate user
$status = $activation = Activation::completed($user);
if ($request->get('activate') != $status) {
if ($request->get('activate')) {
$activation = Activation::exists($user);
if ($activation) {
Activation::complete($user, $activation->code);
}
} else {
//remove existing activation record
Activation::remove($user);
//add new record
Activation::create($user);
//send activation mail
$data = array('user' => $user, 'activationUrl' => URL::route('activate', $user->id, Activation::exists($user)->code));
// Send the activation code through email
Mail::send('emails.register-activate', $data, function ($m) use($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->subject('Welcome ' . $user->first_name);
});
}
}
// Was the user updated?
if ($user->save()) {
// Prepare the success message
$success = Lang::get('users/message.success.update');
// Redirect to the user page
return Redirect::route('admin.users.edit', $user)->with('success', $success);
}
// Prepare the error message
$error = Lang::get('users/message.error.update');
} catch (UserNotFoundException $e) {
// Prepare the error message
$error = Lang::get('users/message.user_not_found', compact('user'));
// Redirect to the user management page
return Redirect::route('users')->with('error', $error);
}
// Redirect to the user page
return Redirect::route('admin.users.edit', $user)->withInput()->with('error', $error);
}
示例8: updatePhoto
/**
* Update the photo on user model resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function updatePhoto(UserRequest $request, $username)
{
$user = User::where(compact('username'))->firstOrFail();
// Check authorisation and throw 404 if not
if (!Auth::user()->allowedTo('edit', 'user', $user)) {
return view('errors/404');
}
$file = $request->file('photo');
$path = "filebank/users/" . $user->id;
$name = "photo." . strtolower($file->getClientOriginalExtension());
$path_name = $path . '/' . $name;
$file->move($path, $name);
Image::make(url($path_name))->fit(740)->save($path_name);
$user->photo = $path_name;
$user->save();
Toastr::success("Saved changes");
return redirect('/user/' . $user->username . '/settings/photo');
}
示例9: update
public function update(UserRequest $request, $id)
{
if ($this->currentUser->hasAccess('wts.user.edit')) {
DB::transaction(function () use($request) {
// Update the user
$user = Sentry::findUserById(Crypt::decrypt($request->id));
if ($request->has('send_sms') && $request->send_sms == 1) {
if ($request->has('password')) {
$user->password = $request->password;
CommonController::sendSms('RHPOZTFYAY', $user->phone, 'Merhaba "' . $user->first_name . ' ' . $user->last_name . '" WTS iş takip sistemi için; \\nEmailiniz : ' . $request->email . ' \\nŞifreniz: ' . $request->password . '\\nGüvenliğiniz açısından şifrenizi kimseyle paylaşmamanızı ve en kısa sürede değiştirmenizi önermekteyiz.\\nSite: wts.pinnacle.com.tr');
} else {
CommonController::sendSms('RHPOZTFYAY', $user->phone, 'Merhaba "' . $user->first_name . ' ' . $user->last_name . '" WTS iş takip sistemi için; \\nEmailiniz : ' . $request->email . '\\nGüvenliğiniz açısından emailinizi kimseyle paylaşmamanızı ve şifrenizi düzenli aralıklarla değiştirmenizi önermekteyiz.\\nSite: wts.pinnacle.com.tr');
}
}
$user->email = $request->email;
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->phone = $request->phone;
$user->slug = $request->slug_name;
$user->save();
// Find the group using the group id
$groupId = Crypt::decrypt($request->group);
if ($user->getGroups()[0]->id != $groupId) {
$newGroup = Sentry::findGroupById($groupId);
$user->updateGroups($newGroup);
}
if ($request->image_hidden) {
$file_path = public_path() . "/uploads/profile-images/" . $user->image;
\File::delete($file_path);
}
if ($request->hasFile('image')) {
$file = $request->file('image');
$imageName = CommonController::imageUpload($file, 'uploads/profile-images');
$user->image = $imageName;
$user->save();
}
});
return response()->json($this->editResponseMessage);
} else {
abort(403, $this->accessForbidden);
}
}
示例10: upload
public function upload(UserRequest $request)
{
$uploaderObj = new Uploader();
$uploaderObj->size = array('width' => 100, 'height' => 100);
$uploaderObj->directory = 'site_user_images';
$resp = $uploaderObj->uploadImage($request->file('user_image_upload'));
return response()->json($resp);
}
示例11: update
public function update(UserRequest $request, $id)
{
$data = $request->all();
$model = Users::find($id);
autoAssignDataToProperty($model, $request->all());
if ($request->hasFile('avatar')) {
$file = $request->file('avatar');
$name = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$picture = time() . $name . '.' . $extension;
$request->file('avatar')->move('images/avatar', $picture);
$filename = 'images/avatar/' . $picture;
} else {
$image = $model->toArray();
$filename = $image['avatar'];
}
$password = bcrypt($request->input('password'));
$model->password = $password;
$model->avatar = $filename;
$model->save();
return redirect()->action('Admin\\UsersController@index')->withSuccess(Lang::get('messages.update_success'));
}
示例12: updateProfile
public function updateProfile(UserRequest $request, Guard $auth)
{
$pathUser = 'profile_picture';
\Storage::makeDirectory($pathUser);
$user = User::findOrFail($auth->id());
$user->fill($request->all());
if ($request->hasFile('avatar')) {
$Documento = $request->file('avatar');
$nombre = \Hash::make($Documento->getClientOriginalName());
$nombre = str_replace('/', 'Y', $nombre);
$nombre = $nombre . '.' . $Documento->guessExtension();
$fullPath = $pathUser . '/' . $nombre;
\Storage::disk('local')->put($fullPath, \File::get($Documento));
$user->avatar = 'documentos/' . $fullPath;
} else {
if ($request->get('delImgProfile') === 'true') {
$user->avatar = 'avatar.jpg';
}
}
$user->save();
return redirect('home');
}
开发者ID:elNapoli,项目名称:iCnca7CrTNYXRF4oxPSidusv17MoVk7CEAhNGFGcYHSu0DNSy7Hkq,代码行数:22,代码来源:UsuariosController.php
示例13: update
public function update(UserRequest $request, $id)
{
//exit('call');
$user = Users::findOrFail($id);
//return $user; exit;
//$user->update($request->all());
if ($request->file('photo')) {
//remove old image
unlink(base_path() . '/public/images/' . $user->image);
$imageName = $user->id . '.' . $request->file('photo')->getClientOriginalExtension();
DB::table('users')->where('id', $id)->update(['name' => $request['name'], 'email' => $request['email'], 'image' => $imageName, 'role' => $request['role']]);
//upload new photo
$request->file('photo')->move(base_path() . '/public/images/', $imageName);
} else {
DB::table('users')->where('id', $id)->update(['name' => $request['name'], 'email' => $request['email'], 'role' => $request['role']]);
}
return redirect('user');
}