我有一个登录模式。当用户登录身份验证失败时,我想使用以下命令重定向回此模式:
控制器
// if Auth Fail
return Redirect::to('/')
->with('error','Username/Password Wrong')
->withInput(Request::except('password'))
->withErrors($validator);
Form
{!! 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>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
{!! Form::close() !!}
正如您在我的图像中看到的那样,似乎显示了错误消息,但旧的用户名输入似乎没有填充。
有人可以纠正我吗?
我是不是忘记做什么了?
Laravel 中完成此类任务最有效的方法是什么?
您可以像这样访问最后的输入:
$username = Request::old('username');
正如所指出的@阿里安·阿科斯塔 https://stackoverflow.com/users/2188595/arian-acosta你可以简单地做
<input type="text" ... value="{{ old('username') }}" ... >
.
如中所述docs https://laravel.com/docs/5.3/requests#old-input在刀片视图中更方便。
控制器中有几种可能性:
代替->withInput(Request::except('password'))
do:
a) Input::flash();
or:
b) Input::flashExcept('password');
并重定向到视图:
a) ->withInput(Input::except('password'));
分别。和:
b) ->withInput();
The 有关旧输入的文档 http://laravel.com/docs/5.0/requests#old-input供进一步阅读...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)