How can I make a password update on a user logged in to Laravel 5.2?

0

I was trying to change the user's password, but it did not work, someone can help me I'm new to Laravel.

public function updatePassword()
{  
    $user = Auth::user();
    $user->password = bcrypt($request['newpassword']);
    $user->save();
}

The solution I found to the problem was this

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Validator;

use Illuminate\Http\Request;

use App\Http\Requests;

use Auth;

use Image;

use Hash;

use App\User;

    public function password(){
        return View('user.password');
    }

    public function updatePassword(Request $request){
        $rules = [
            'mypassword' => 'required',
            'password' => 'required|confirmed|min:6|max:32',
        ];

        $messages = [
            'mypassword.required' => 'Campo obrigatorio',
            'password.required' => 'Campo obrigatorio',
            'password.confirmed' => 'As senhas de redefinição não são iguais',
            'password.min' => 'A senha deve possuir no mínimo 6 caracteres.',
            'password.max' => 'A senha deve possuir no maxímo 32 caracteres.',
        ];

        $validator = Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()){
            return redirect('user/password')->withErrors($validator);
        }
        else{
            if (Hash::check($request->mypassword, Auth::user()->password)){
                $user = new User;
                $user->where('email', '=', Auth::user()->email)
                     ->update(['password' => bcrypt($request->password)]);

                return redirect('user/password')->with('status', 'Senha alterada com sucesso');
            }
            else
            {
                return redirect('user/password')->with('message', 'O token para troca de senha é inválido.');
            }
        }
    }
    
asked by anonymous 01.04.2017 / 05:37

1 answer

0
___ erkimt ___ How can I make a password update on a user logged in to Laravel 5.2? ______ qstntxt ___

I was trying to change the user's password, but it did not work, someone can help me I'm new to Laravel.

function updatePassword(Request $request){
    //validar password
    $this->validate($request, [
        'password'  => 'min:6|confirmed'
    ]);

    // Atualizar usuário
    Auth::user()->update($request->input('password'));
}

The solution I found to the problem was this

function updatePassword(Request $request){
    //validar password
    $this->validate($request, [
        'password'  => 'min:6|confirmed'
    ]);

    // Atualizar usuário
    Auth::user()->update($request->input('password'));
}
    
______ ___ azszpr194409

You can do the following:

%pre%     
___
01.04.2017 / 15:15