laravel withInput() 和old()

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cofecode/article/details/86591495

传统提交表单 页面会刷新,输入框里的内容会丢失掉。

更好的用户体验 解决办法withInput() + old()

laravel 会自动把用户输入的数据存到一次性的session里。

使用old()可以将上次提交的数据从一次性session里取出来,挂在DOM元素上,从而避免用户重新输入。

使用withInput(),配合with方法,可以将想要返回的参数写入session中。blade模板便可以从session中取出值,来做一些逻辑判断。

return redirect()-> back()->withInput()->with(['error'=>'注册失败,短信验证码不正确','page'=>'phone']);

blade模板old()赋值函数写法

<input type="text" name="username" value="{{ old('username') }}">

猜你喜欢

转载自blog.csdn.net/cofecode/article/details/86591495
old