Ad
Laravel Update User Password From Form With Hash
So I have this form with 3 fields (User Email, Password and Password Confirm). this form posts to a route that takes me to the following controller:
public function updateUser($id, Request $request){
//validate post data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$request->all();
$request['email'] = $request['email'];
$request['password'] = Hash::make($request['password']);
$postData = [$request['email'], $request['password']];
User::find($id)->update($postData);
//store status message
Session::flash('success_msg', 'User details updated successfully!');
return redirect()->route('admin.user');
}
The problem is, this code is not updating my database at all although it gives me no errors.
Basically what I am trying to do is that I want to allow the administrator to change the default account details within the admin panel. The default admin details are created by a seeder once the app is installed. (This app is single user - only the admin)
Thank you all!
Ad
Answer
You have to pass key of array so that column can be identify.
public function updateUser($id, Request $request){
//validate post data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$userData = $request->only(["email","password"]);
$userData['password'] = Hash::make($userData['password']);
User::find($id)->update($userData);
Session::flash('success_msg', 'User details updated successfully!');
return redirect()->route('admin.user');
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected
Ad