In my view1
I have a post form, with the action to a post route.
The post function in the controller saves the request's data to a session and redirects to view2
.
In that view I want to have a link to navigate back to view1
but with the form filled out.
For validation purposes, I already have old()
in place.
I expected the follow to work, but the function does not exists on the route helper:
← <a href="{{ route('view1')->withInput() }}">Back</a>
Here is the controller:
public function view1()
{
return view('view1');
}
public function post_create(CreateRequest $request)
{
$request->session()->put('data', $request->all());
return redirect()->route('view2');
}
public function view2()
{
return view('view2', [
'data' => session('data'),
]);
}
CodePudding user response:
If you have stored that data in session so why are you not retrieving data from session.
Like this
session("key") ? session("key") : old("key") ? old("key") : ""
Or
if(session("key")) { return session("key"); } elseif (old("key")) { return old("key"); } else { return ""; }
It will check if session has data so it get data from session and check in elseif part old field has data or not and else do nothing