简体   繁体   中英

If the typed password does not match the logged in user password show validation

Hi there how can I put validation to appear bottom input with red on Laravel

  public function initiateAccountDeletion(Request $request){


        $validator = Validator::make($request->all(),[
            'password' => 'required'
        ]); 

        if($validator->fails()){
            return response()->json(['success' => 0, 'message' => 'Could not initite the account deletion because of validation fail!'], 422);
        } 

        if ((Hash::check($request['password'], Auth::user()->password))) {

            $user = Auth::user();
            $code = $this->generateDeletionCode();

            UserDeletionCode::create(['user_id' => Auth::user()->id,
                                      'code'    => $code]);

            Mail::to(Auth::user()->email)->send(new AccountDeletion($user, $code));

            return redirect()->back()->with(['status' => Lang::get('general.delete_account_success_message')]); 
        }else{  
            return redirect()->back()->with(['errori' => Lang::get('general.please_enter_current_pass')]); 

        }  
    }

And here is my input inside my form but i am showing only this part

   <div class="form-group floating-label {{ $errors->has('password') ? ' has-error' : '' }}">

                                <input class="form-control" name="password"  id="regular2" type="password" required>
                                <label for="regular2">@lang('android.user_login_email_password')</label>
                                @if ($errors->has('password'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('password') }}</strong>
                                </span>
                                @endif 
                            </div>

So what I need is the error to appear to this {{ $errors->first('password') }}

you have typo

return redirect()->back()->with(['errori' => Lang::get('general.please_enter_current_pass')]); 

it should be

return redirect()->back()->with(['errors' => Lang::get('general.please_enter_current_pass')]);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM