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!
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');
}