06.10.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

HTTP Requests 153<br />

Flashing Input To The Session<br />

The flash method on the Illuminate\Http\Request instance will flash the current input to the<br />

session so that it is available during the user’s next request to the application:<br />

1 $request->flash();<br />

You may also use the flashOnly and flashExcept methods to flash a sub-set of the request data<br />

into the session:<br />

1 $request->flashOnly(['username', 'email']);<br />

2<br />

3 $request->flashExcept('password');<br />

Flash Input Into Session Then Redirect<br />

Since you often will want to flash input in association with a redirect to the previous page, you may<br />

easily chain input flashing onto a redirect using the withInput method:<br />

1 return redirect('form')->withInput();<br />

2<br />

3 return redirect('form')->withInput($request->except('password'));<br />

Retrieving Old Data<br />

To retrieve flashed input from the previous request, use the old method on the Request instance.<br />

The old method provides a convenient helper for pulling the flashed input data out of the session:<br />

1 $username = $request->old('username');<br />

Laravel also provides a global old helper function. If you are displaying old input within a Blade<br />

template, it is more convenient to use the old helper. If no old input exists for the given string, null<br />

will be returned:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!