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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With