0
I am trying to perform a simple function to change the password of the logged in user using the code:
$user = User::find(\Auth::user()->idusuario);
$user->password = bcrypt($request['novasenha']);
$user->save();
But it doesn’t work. I noticed that the executed query does not take user id:
update USUARIOS set password = ? where IDUSUARIO is null
I realized that this problem of "where IDUSUARIO is null
" also repeats in other situations. How should I do this? Because it does not take the id that is being passed?
<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = "USUARIOS";
protected $primaryKey = 'IDUSUARIO';
public $timestamps = false;
/**
* The database table used by the model.
*
* @var string
*/
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'idusuario', 'nomerazao', 'email', 'cpfcnpj', 'telefone', 'idperfil', 'situacao', 'password'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getAuthIdentifier()
{
// TODO: Implement getAuthIdentifier() method.
return $this->attributes['idusuario'];
}
public function regras(){
return $this->belongsToMany('App\Models\RegrasModel', 'REGRASUSUARIOS', 'IDUSUARIO', 'IDREGRA');
}
}
Your update says to update the password of everyone who has it null, ie more than one user can be affected.
– rray
If I’m not mistaken
Auth::user()
will return an instance ofUser
ai does not need theUser::find(...)
, could stayAuth::user()->password = bcrypt($request['novasenha'])
. Put as this your Model User.– Neuber Oliveira
I’ve tried using it like this, and I got the same result.
– user11683