In laravel, the old() method is used to take out the information in the session. The syntax is "value="{{old('name')}}""; when the form submission fails, laravel will Flash the data entered by the user into a one-time session, and old can retrieve the flash data.
#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.
Since the error message will be flashed into the session, the old function takes out the information in the session
value="{{old('name')}}"
When the user submits the form After failure, Laravel will automatically flash the user's input data into a one-time session (this data will be lost as soon as it is refreshed, so it is called one-time data). Then old(‘name’) can take out the flash memory data in the session, thus preventing the user from re-entering it.
Using old() can take out the last submitted data from the one-time session and hang it on the DOM element, thus preventing the user from re-entering.
The example is as follows:
The traditional submission form page will be refreshed and the content in the input box will be lost. laravel
Better user experience Solution withInput() old()session
laravel will automatically save the data entered by the user into a one-time session. Function
Using old() can take out the last submitted data from the one-time session and hang it on the DOM element, thus preventing the user from re-entering it. input
Use withInput() and the with method to write the parameters you want to return into the session. The blade template can take out the value from the session to make some logical judgments. it
return redirect()-> back()->withInput()->with(['error'=>'注册失败,短信验证码不正确','page'=>'phone']);
blade template old() assignment function writing method io
<input type="text" name="username" value="{{ old('username') }}">
[Related recommendations: laravel video tutorial]
The above is the detailed content of How to use old method in laravel. For more information, please follow other related articles on the PHP Chinese website!