1

i'm developing a web app with Laravel. I'm new with this amazing framework and i'm still learning.

My problem: i would to use

return back();

at the end of a method of controller, but passing to the back page some post data.

Example of what i want to do:

return back()->withPostData(['id'=>'10']);

Is possible to do that with Laravel?

Simone Giusti
  • 313
  • 5
  • 16

2 Answers2

3

You can try as:

Redirect::back()->withInput();

From the docs..

To retrieve flashed input from the previous request, use the old method on the Request instance:

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

Docs

Amit Gupta
  • 17,072
  • 4
  • 41
  • 53
1

You can use session to pass the data:

return redirect()->back()->with('id', 10);

And then get data with session('id').

But if you're using forms and just want to get old data, you should use simple redirect and old() method:

<input type="text" name="id" value="{{ old('id') }}">
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279