Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

richardh's avatar

Redirect::to passing variable to view

I have need to send some data back to the view from a function that returns this: return Redirect::to($request->input('success_url')); I have tried using ->with but I always get the error $donation is not defined I also tried compact but same issue return Redirect::to($request->input('success_url'), compact('donation',[$res]));

Is there a way to return data back so i can use it in my view.

0 likes
6 replies
36864's avatar

Passing data on a redirect will make it available to the controller that handles the request after redirecting, you'll need to pass the data into the view from that controller.

1 like
richardh's avatar

In the MainController it just returns: return $donation but there is a laravel api call that looks like this: $res = $this->api->post('donation/create', $request->all())->json(); this then posts to the MainController should I be sending my return fro the MainController

richardh's avatar

How do I then use my new session variable

tykus's avatar
tykus
Best Answer
Level 104

The data flashed to the session will be available using session('data') or session()->get('data')

You will hit a controller method (presuming one is set up for URI), so you could assign to a variable in the controller; or you could use the session() helper directly in the view

Please or to participate in this conversation.