What does the old() method in laravel template do?
巴扎黑2017-05-16 16:54:06
You can use phpstorm and then command+b to view its source code,
if (! function_exists('old')) {
/**
Retrieve an old input item.
*
@param string $key
@param mixed $default
@return mixed
*/
old($key = null, $default = null)
{
return app('request')->old($key, $default);
}
}
In fact, this also points to request
阿神2017-05-16 16:54:06
Can be used to receive old input data returned by the validate object. In this way, users can know what data they filled in before when verification fails.
仅有的幸福2017-05-16 16:54:06
For example, when posting to an address and verifying data errors, you have to return to the previous page. For a better user experience, the filled-in information will be saved in the flash session and displayed on the previous page.
This way users won’t make mistakes after painstakingly filling in a lot of form data, and then go back and refill it.
某草草2017-05-16 16:54:06
Documentation: http://laravel-china.org/docs...
Old input data
When the user fails to submit the form, 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('input_name') can take out the flash memory data in the session, thereby preventing the user from re-entering.
<input type="text" name="input_name" value="{{ old('input_name') }}" />