Tuesday, May 8, 2018

Redirect back with input not working in laravel 5.5 - development

Redirect back with input not working in laravel 5.5

I’ve used redirect back with input many times previously. But in this project I’m unable to do so. This is my controller method that handles the form request:

public function verifyMobileCode( Request $request)
{
        $userId = Auth::user()->id;
        if( Auth::user()->verification_code == $request['verification_code'])
        {
            User::where('id', $userId)->update(['verified'=>1]);
            return redirect('/')->with('success', 'Account verified.');
        }
        else
        {
            return redirect()->back()->withErrors('verification_code' ,'unv' )->withInput($request->all());
        }
}

This is my form blade:

@extends('layouts.index')

@section('content')

<div class="container" style='padding-top: 150px;'>

    <?php var_dump($errors) ; ?>
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Verify your mobile</div>

                <div class="panel-body">
                    <form class="form-horizontal" method="POST" action="">
                        

                        <div class="form-group">
                            <label for="verification_code" class="col-md-4 control-label">Verification code</label>

                            <div class="col-md-6">
                                <input id="verification_code" type="text" class="form-control" name="verification_code" value="{!! old('verification_code') !!}" required autofocus maxlength="6" pattern="d{6}">

                                @if ($errors->has('verification_code'))
                                    <span class="help-block">
                                        <strong>Please enter 6 digit number sent to your mobile.</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Register
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

I do not find any error or something wrong. Is there anything you see? Is there any technique to debug this behaviour? Thaks in advance.



from Laravel Questions and Answers https://laravelquestions.com/laravel/redirect-back-with-input-not-working-in-laravel-5-5/
via Lzo Media

No comments:

Post a Comment