2017-04-19 34 views
0

Ich versuche, das Passwort zu ändern, indem alte Passwort funktioniert es gut, aber was mein Problem ist, wenn ich versuche, mein Feld zu aktualisieren es speichern Neuer Passwortwert als leer (weil ich dieses Feld leer lasse) Ich möchte das neue Passwort nur aktualisieren, wenn ich den neuen Passwortwert ändere oder das aktuelle Passwort im neuen PasswortfeldAktualisieren Sie den Passwort-Wert nur, wenn ich das Passwort ändern oder sonst behält es den gleichen Wert

hier in meinem Controller

public function profileupdate(Request $request,$id) 
    { 
    if(Auth::Check()) 
    { 

     $request_data = $request->All(); 
     $validator = $this->validator($request_data); 
     if($validator->fails()) 
     { 
     $this->throwValidationException($request, $validator); 
     } 

    else 
    { 
     $current_password = Auth::User()->password; 
     if(Hash::check($request_data['current-password'], $current_password)) 
     { 
     $user_id = Auth::User()->id;      
     $admin = Admin::find($user_id);   
     $admin->update([ 
      'name'=>$request['name'], 
      'job_title'=> $request['job_title'], 
      'email'=>$request['email'], 
      'phone_number'=>$request['phone_number'], 
      'password'=> Hash::make($request['password']), 
     ]); 
     return redirect('/admin/profile') 
      ->with('message', 'Admin Profile updated successfuly!'); 
     } 
     else 
     { 
      return redirect('/admin/profile') 
     ->with('password', 'Please enter correct password!'); 
     } 
    }   
    } 
    else 
    { 
    return redirect()->to('/'); 
    }  
} 

Innerhalb meiner Sicht

<div class="control-group{{ $errors->has('current-password') ? ' has-error' : '' }}"> 
          <label class="control-label"> Current Password:</label> 
          <div class="controls"> 
           <input type="password" class="form-control" id="current-password" name="current-password" placeholder="Password"> 
           @if(Session::has('password')) <span class="help-inline"> <strong>{{Session::get('password')}} </strong></span> @endif 
           @if ($errors->has('current-password')) 
               <span class="help-inline"> 
                <strong>{{ $errors->first('current-password') }}</strong> 
               </span> 
          @endif 
          </div> 
        </div> 
        <div class="control-group{{ $errors->has('password') ? ' has-error' : '' }}"> 
          <label class="control-label"> New Password:</label> 
          <div class="controls"> 
           <input type="password" class="form-control" id="password" name="password" placeholder="Password"> 
           @if ($errors->has('password')) 
               <span class="help-inline"> 
                <strong>{{ $errors->first('password') }}</strong> 
               </span> 
          @endif 
          </div> 
        </div> 
        <div class="control-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> 
           <label class="control-label">Confirm Password:</label> 
           <div class="controls"> 
           <input type="password" class="form-control" id="password_confirmation" name="password_confirmation" placeholder="Re-enter Password"> 
           @if ($errors->has('password_confirmation')) 
               <span class="help-inline"> 
                <strong>{{ $errors->first('password_confirmation') }}</strong> 
               </span> 
          @endif 
           </div> 
        </div> 
+0

wo sind die Validierungsregeln? Es sollte nicht bestehen, wenn es leer ist, versuchen Sie auch 'var_dump' die Anfrage, um die Felder und ihre Werte zu sehen. – Gntem

Antwort

0

Erstellen Sie einfach das Array, das die Werte dynamisch statt statisch aktualisiert. Der Großteil des Arrays ist immer noch statisch, aber das Kennwort wird jetzt dynamisch hinzugefügt, abhängig davon, ob ein Wert an das Feld password in Ihrem Formular übergeben wurde.

// Values which are always updated 
$update_values = [ 
    'name'=>$request['name'], 
    'job_title'=> $request['job_title'], 
    'email'=>$request['email'], 
    'phone_number'=>$request['phone_number'] 
]; 
// If the password-field isn't empty, we add it to the values that are updated 
if (!empty($request['password'])) 
    $update_values['password'] = Hash::make($request['password']); 

// Execute the update 
$admin->update($update_values); 
Verwandte Themen