Laravel save() returns true but does not change anything in the database

Asked

Viewed 55 times

0

I’m trying to do an UPDATE to change my user’s password, the function is returning me SUCCESS, but when I go in the database nothing has changed. I am doing a post via Postman, for the following route "http://localhost:8000/api/issuer/3", in my body I am sending the current password and the new password via x.www.form.urlencoded. When I do the validation if the current password is different from the one typed it returns me 'Passwords do not check' until then everything OK, but when it is to change the password via save() it does not change in the bank.

my route

Route::post("emitente/{emit}", "EmitsController@alteraSenha");

my model

  namespace App;

use Illuminate\Database\Eloquent\Model;

class Emit extends Model
{
    protected $table = 'emit';
    protected $fillable = ['senhaUsu'];    
    
}

my controller

 public function alteraSenha(request $request , Emit $emit){
    
    if(($emit->senhaUsu == $request->input('atual')) AND (!empty($request->input('nova')))){
        
        $emit->senhaUsu = $request->input('nova');
        
        if($emit->save()){ 

            return response()->json(['status'=>'sucesso']);
        }    
            
    }else{
        return response()->json(['status'=>'Senhas não conferem']);
    }  

} 
  • includes the return of var_dump($emit) (before if($emit->save())) in the question so that there is more information and so we can help

  • I put var_dump($Emit), it returns me 2 objects, one with the changes I just made in the password fieldUsu, and another "original" with the information coming from the bank. Object(App Emit)#263 (26) {[ "passwordUsu" ]=> string(4) "1233" [} "original":protected ]=>[ "passwordUsu" ]=> string(7) "dom1234" [

  • Obs: I am using Clickable localhost, and my bank is online

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.