By John Koster
old($key = null, $default = null)
The old
helper function is used to retrieve an old input item. It is a shortcut to calling the Illuminate\Http\Request::old
instance method. It accepts a $key
argument and a $default
argument. They $key
should be the name of the input item to retrieve and a $default
value can be supplied that will be returned if the given $key
does not exist.
The following example demonstrates how to use the old
helper function and assumes that an input item with the key name
exits:
1<?php
2
3// Retrieve the old name.
4$userName = old('name');
5
6// Retrieve the old name with
7// a default value.
8$userName = old('name', 'John Doe');
The examples below demonstrate different methods to achieve the same result:
1<?php
2
3use Illuminate\Facades\Input;
4
5// Retrieve the old name using the Input facade:
6$userName = Input::old('name');
7
8// Retrieve the old name using the request()
9// helper function:
10$userName = request()->old('name');
∎