传统提交表单 页面会刷新,输入框里的内容会丢失掉。laravel
更好的用户体验 解决办法withInput() + old()session
laravel 会自动把用户输入的数据存到一次性的session里。函数
使用old()能够将上次提交的数据从一次性session里取出来,挂在DOM元素上,从而避免用户从新输入。input
使用withInput(),配合with方法,能够将想要返回的参数写入session中。blade模板即可以从session中取出值,来作一些逻辑判断。it
return redirect()-> back()->withInput()->with(['error'=>'注册失败,短信验证码不正确','page'=>'phone']);
1
blade模板old()赋值函数写法io
<input type="text" name="username" value="{{ old('username') }}">
验证码