Search

Laravel 5: Accessing Session Input Data With old

April 14, 2018 —John Koster

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.

#Signature

The signature of the old function is:

1function old(
2 $key = null,
3 $default = null
4);

#Example Use

The following example demonstrates how to use the old helper function and assumes that an input item with the key name exits:

1// Retrieve the old name.
2$userName = old('name');
3 
4// Retrieve the old name with
5// a default value.
6$userName = old('name', 'John Doe');

The examples below demonstrate different methods to achieve the same result:

1use Illuminate\Facades\Input;
2 
3// Retrieve the old name using the Input facade:
4$userName = Input::old('name');
5 
6// Retrieve the old name using the request()
7// helper function:
8$userName = request()->old('name');

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.