Home  >  Article  >  PHP Framework  >  How to use old method in laravel

How to use old method in laravel

WBOY
WBOYOriginal
2022-02-18 10:44:133101browse

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.

How to use old method in laravel

#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.

How to use the old method in laravel

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(&#39;username&#39;) }}">

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn