我有一个登录模式。当用户登录通过身份验证失败时,我想使用以下命令重定向回此模式:
// if Auth Fail
return Redirect::to('/')
->with('error','Username/Password Wrong')
->withInput(Request::except('password'))
->withErrors($validator);
{!! 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');
正如@Arian Acosta所指出的,您只需
<input type="text" ... value="{{ old('username') }}" ... >
。
如文档中所述,在刀片视图中更加方便。
控制器中有几种可能性:
代替 ->withInput(Request::except('password'))
做:
一种) Input::flash();
要么:
b) Input::flashExcept('password');
并使用以下命令重定向到视图:
一种) ->withInput(Input::except('password'));
分别 与:
b) ->withInput();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句