Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 withInput old always empty

I'm building a simple login form using Laravel 5 and I would like to fill some inputs by default when some error occurred. My router is calling these functions as given

Route::get('/login','AuthController@login');
Route::post('/login','AuthController@do_login');

My Controller is like showed below

namespace App\Http\Controllers;
use App;
use App\Models\User;
use Request;
use Illuminate\Support\Facades\Redirect;

class AuthController extends Controller {

   function login()
   {
       if(User::check())
       {
           /*User is logged, then cannot login*/
           return Redirect::back();
       }
       else
       {
           return view('auth.login');
       }
   }
    function do_login()
    {
        return view('auth.login')->withInput(Request::except("password"));
    }

}

Noticing that withInput is being underlined by PhpStorm saying that can't find it's implementation in Illuminate\View\View. Inside my view, i have the following:

            {!! Form::open() !!}
            <div class="form-group">
                {!! Form::text('email', Input::old('email'), array('placeholder' => Lang::get('auth.email'), 'class' => 'form-control')) !!}
            </div>
            <div class="form-group">
                {!! Form::password('password', array('placeholder' => Lang::get('auth.password'),'class'=>'form-control')) !!}
            </div>
            <div class="form-group">
                <button class="btn btn-primary btn-block">@lang('auth.signin')</button>
                <span class="pull-right"><a href="/{{App::getLocale()}}/register">@lang('auth.register')</a></span>
            </div>
        <input type="email" class="form-control" name="email" value="{{ old('email') }}">
        {!! Form::close() !!}

What am I missing here? This can be done in Laravel 5 ? Many thanks for your time!

like image 311
Diogo Mendonça Avatar asked Jun 30 '15 20:06

Diogo Mendonça


1 Answers

withInput() is for preserving the input during redirects.

It is not necessary (nor possible) to call it if you're doing a return view().

You might consider having your do_login do return redirect()->back()->withInput(Request::except("password")); though, to properly implement Post/Redirect/Get.

like image 191
ceejayoz Avatar answered Oct 16 '22 03:10

ceejayoz