本文整理汇总了PHP中App\Http\Requests\UserRequest::has方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRequest::has方法的具体用法?PHP UserRequest::has怎么用?PHP UserRequest::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Requests\UserRequest
的用法示例。
在下文中一共展示了UserRequest::has方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(UserRequest $request)
{
$input = $request->except('roles');
if ($request->has('password')) {
$input['password'] = bcrypt($request->password);
} else {
unset($input['password']);
}
$record = $this->model->create($input);
if ($request->has('roles')) {
$record->syncRoles($request->roles);
}
$this->notify(['type' => 'success', 'title' => 'Successful create user!', 'description' => 'User is created successfully!']);
return redirect(route('user.edit', ['id' => $record->id]));
}
示例2: postLogin
protected function postLogin(UserRequest $request)
{
if (Auth::attempt($request->only('email', 'password'), $request->has('remember_me'))) {
return Redirect::intended();
}
return Redirect::route('login')->withInput($request->only('email', 'remember_me'))->withErrors(['email' => Lang::get('auth.email_error_login')]);
}
示例3: update
public function update($id, UserRequest $request)
{
$data = $request->has('password') ? $request->all() : $request->except('password');
$this->user->save($id, $data);
if ($request->ajax()) {
return response()->json(['status' => trans('messages.saved'), 'type' => 'success']);
}
$route = $request->get('task') == 'apply' ? route('admin.users.edit', $id) : route('admin.users.index');
return redirect($route)->with(['status' => trans('messages.saved'), 'type' => 'success']);
}
示例4: 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);
}
示例5: changePassword
/**
* Endpoint for changing the password.
*/
public function changePassword(UserRequest $request)
{
// Get authenticated user
$user = \Auth::user();
// Get subset of actual input fields to consider
$input = $request->getValidInputs();
// Hash password
$input['password'] = \Hash::make($input['password']);
// Update user object
$user->update($input);
\Notifications::add('Your password has been changed.', 'success');
if ($request->has('_redirect_url')) {
return redirect($request->get('_redirect_url'));
} else {
return redirect()->route('user.settings');
}
}
示例6: 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);
}
}
示例7: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @param UserRequest $request
* @return Response
*/
public function update($id, UserRequest $request)
{
$user = Sentinel::findById($id);
$credentials = $request->only(['first_name', 'last_name', 'email']);
if ($request->has('password')) {
$credentials['password'] = $request->get('password');
}
$valid = Sentinel::getUserRepository()->validForUpdate($user, $credentials);
if ($valid === false) {
echo 'error';
return false;
}
Sentinel::getUserRepository()->update($user, $credentials);
if ($request->get('active') != Activation::completed($user)) {
if ($request->get('active')) {
$activation = Activation::create($user);
Activation::complete($user, $activation->code);
} else {
Activation::remove($user);
}
}
$roles = Sentinel::getRoleRepository()->all();
$wantedRoles = $request->get('role');
foreach ($roles as $role) {
if (in_array($role->id, $wantedRoles) && !$user->inRole($role)) {
$role->users()->attach($user);
} elseif (!in_array($role->id, $wantedRoles) && $user->inRole($role)) {
$role->users()->detach($user);
}
}
return redirect()->route('admin.users.show', [$user->id]);
}
示例8: update
public static function update(UserRequest $request, $id)
{
$user = User::find($id);
if (!$user) {
return redirect()->back()->withErrors('No se encontro el usuario solicitado');
}
$role = Role::select('name', 'id')->where('id', '=', $request->input('role_id'))->first();
if ($role->name == 'Admin') {
//Admin
$user->role_id = $role->id;
} else {
//Client
$client = Role::select('id')->where('name', '=', 'User')->first();
//$token = str_random(32);
$user->role_id = $client->id;
//$user->active = 0;
}
if (!$request->has('active')) {
//check checkbox :D
$user->active = 0;
} else {
$user->active = $request->input('active');
}
$user->password = Hash::make($request->input('password'));
$user->name = $request->input('name');
$user->lastname = $request->input('lastname');
$user->email = $request->input('email');
$user->dni = $request->input('dni');
$user->state_id = $request->input('state_id');
$user->city_id = $request->input('city_id');
$user->save();
return redirect()->route('users.index')->with('success', 'El usuario se ha modificado correctamente');
}