dimanche 3 décembre 2017

Laravel validation with exist function

I have laravel change password code, with fields: oldpassword, newpasword, confirmedpassword Now to validate the form the newpasword must be the same as confirmedpassword, and the old must be existed for this user in database

this is my view code:

<div class="form-group">
<label for="oldpsw">your current password</label>
<input type="password" class="form-control" id="oldpsw" 
placeholder="your current password" name="oldpsw">
@if ($errors->has('oldpsw'))
<span class="help-block">
<strong></strong>
</span>
@endif
</div>
<div class="form-group">
<label for="password">new password</label>
<input type="password" class="form-control" id="password" placeholder="new 
password" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong></strong>
</span>
@endif
</div>
<div class="form-group">
<label for="password_confirmation">Password Confirmation</label>
<input type="password" class="form-control" id="password_confirmation" 
placeholder="Password Confirmation"  name="password_confirmation" required>
</div>

my controller:

return Validator::make($data, ['oldpsw' =>   'required|string','password' =>   'required|string|confirmed','password_confirmation' => 'required|string',
  'password' =>Rule::exists('accounts')->where(function ($query) { $query->where('student_no', Auth::user()->student_no);}), ]);

If I want to use |confirmed my field must be as the name of model fillable field, but if I want to check the db existence it requires the field also as the same column in db. My Db column is:password, what can I do to solve this problem



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire