Roman Ganoshenko Roman Ganoshenko - 3 months ago 24
PHP Question

Redirect back with input Laravel

So i am totally done ;( I can't understand how to redirect back on Laravel with filled inputs

My simple code is:

public function postSignIn(Request $request)
{
return redirect()->back()->withInput();
}


My view blade is:

<form action="{{ route('signin') }}" method="post">
<div class="form-group {{$errors->has('in_email') ? 'has-error' : ''}}">
<label for="email">Your E-Mail</label>
<input class="form-control" type="text" name="in_email" id="email">
@if ($errors->has('in_email'))
<span class="help-block">{{$errors->first('in_email')}}</span>
@endif
</div>

<div class="form-group {{$errors->has('in_password') ? 'has-error' : ''}}">
<label for="password">Your Password</label>
<input class="form-control" type="password" name="in_password" id="password">
@if ($errors->has('in_password'))
<span class="help-block">{{$errors->first('in_password')}}</span>
@endif
</div>
{{ csrf_field() }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>


But every time all inputs are empty

What i am doing wrong?

thx

Answer

You need to use old for all elements you need input, see example below:

<form action="{{ route('signin') }}" method="post">
        <div class="form-group {{$errors->has('in_email') ? 'has-error' : ''}}">
                <label for="email">Your E-Mail</label>
                <input class="form-control" type="text" name="in_email" id="email" value="{{ old('in_email') }}">
                @if ($errors->has('in_email'))
                        <span class="help-block">{{$errors->first('in_email')}}</span>
                @endif
        </div>

        <div class="form-group {{$errors->has('in_password') ? 'has-error' : ''}}">
                <label for="password">Your Password</label>
                <input class="form-control" type="password" name="in_password" id="password" value="{{ old('in_password') }}">
                @if ($errors->has('in_password'))
                        <span class="help-block">{{$errors->first('in_password')}}</span>
                @endif
        </div>
        {{ csrf_field() }}
        <button type="submit" class="btn btn-primary">Submit</button>
</form>