ihue ihue - 3 months ago 19
PHP Question

How can I redirect with old input in Laravel?

I have a login modal. When the user log-in fail the authentication, I want to redirect back to this modal with :

  • error message(s)

  • and old input(s).

enter image description here


// if Auth Fail
return Redirect::to('/')
->with('error','Username/Password Wrong')


{!! Form::open(array('url' => '/', 'class' => 'login-form')) !!}

<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Enter Username" required>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
<button type="submit" class="btn btn-primary">Login</button>

{!! Form::close() !!}

As you can see as part of my image, the error message seem to display, but the old input of username doesn't seem to populate.

Can someone please correct me ?
Did I forget to do anything ?
What is the most efficient way in Laravel to accomplish something like this ?


In the view you can access it like so: {{Request::old('username')}}

<input type="text" ... value="{{Request::old('username')}}" required>

In the controller you could also do the following:

Instead of ->withInput(Request::except('password'))


a) Input::flash();


b) Input::flashExcept('password');

and redirect to the view with:

a) ->withInput(Input::except('password'));

resp. with:

b) ->withInput();

The docs about Old Input for further reading...