What Is An Old Input In Laravel Framework with Example

admin_img Posted By Bajarangi soft , Posted On 17-09-2020

Laravel allows you to keep input from one request during the next request. This feature is particularly useful for re-populating forms after detecting validation errors. However, if you are using Laravel's included validation features, it is unlikely you will need to manually use these methods, as some of Laravel's built-in validation facilities will call them automatically.

What Is An Old Input In Laravel Framework with Example

Flashing Input To The Session

The flash method on the Illuminate\Http\Request class will flash the current input to the session so that it is available during the user's next request to the application:
 

$request->flash();


You may also use the flashOnly and flashExcept methods to flash a subset of the request data to the session. These methods are useful for keeping sensitive information such as passwords out of the session:
$request->flashOnly(['username', 'email']);

$request->flashExcept('password');


Flashing Input Then Redirecting
 

Since you often will want to flash input to the session and then redirect to the previous page, you may easily chain input flashing onto a redirect using the withInput method:

return redirect('form')->withInput();

return redirect('form')->withInput(
$request->except('password')
);
 

Retrieving Old Input

To retrieve flashed input from the previous request, use the old method on the Request instance. The old method will pull the previously flashed input data from the session:

$username = $request->old('username');


Laravel also provides a global old helper. If you are displaying old input within a Blade template, it is more convenient to use the old helper. If no old input exists for the given field, null will be returned:
<input type="text" name="username" value="{{ old('username') }}">


To know more about Retrieve Input Data In Laravel visit our Bajarangisoft site.

Related Post