Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 input old is empty

My routes is here

Route::get('sign-up', ['as' => 'signUp', 'uses' => 'UserController@signUpGet']);
Route::post('sign-up', ['as' => 'signUpPost', 'uses' => 'UserController@signUpPost']);

Controller

return redirect('signUp')->withInput();

And View

    <form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

The {{old()}} function return empty value.
EDIT
I took

NotFoundHttpException in RouteCollection.php line 145:
like image 812
balkondemiri Avatar asked Feb 20 '15 08:02

balkondemiri


2 Answers

Your problem looks like you are not actually submitting the username in the first place:

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

There is no 'submit' button inside the form. If you submit outside the form - then the username will not be included.

Add the submit button inside your form - then try again

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
        <input type="submit" value="Submit">
</form>

Edit - also your controller is wrong. It should be this:

 return redirect()->route('signUp')->withInput();
like image 61
Laurence Avatar answered Oct 24 '22 19:10

Laurence


All you are missing is to Flash the Input to the session. This is so it's available during the next request.

     $request->flash();

Do that just before calling to View your form.

Source: http://laravel.com/docs/5.1/requests#old-input

like image 13
Alex Avatar answered Oct 24 '22 17:10

Alex