我有一个登录模式.当用户登录失败认证时,我想重定向到这个模式:
>错误消息
>和旧输入.
调节器
// 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')}}”...>
如docs所述,它在刀片视图中更加方便.
控制器有几种可能性:
代替
– > withInput(请求::除( ‘密码’))
做:
a)Input :: flash();
要么:
b)Input :: flashExcept(‘password’);
并重定向到视图:
a) – > withInput(Input :: except(‘password’));
RESP.有:
b) – & withinput();
docs about Old Input进一步阅读…