I'm trying to perform a simple function to change the password of the user logged in using the code:
$user = User::find(\Auth::user()->idusuario);
$user->password = bcrypt($request['novasenha']);
$user->save();
But, it does not work. I noticed that the executed query does not take the id of the user:
update USUARIOS set password = ? where IDUSUARIO is null
I noticed that this problem of " where IDUSUARIO is null
" is also repeated in other situations. How should I proceed with this? Why does not he get the id 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');
}
}