My goal is to pass object from current function to other function. As you can see the codes below, I have provided a multiple return
approach I've done in the controller section. I have commented each of its error. I am not sure why that is happened although some of the approaches are from the voted answer in some other questions.
Array Content [ dump($data = $request->all()); ]
Controller
public function supply_status(Request $request, $data)
{
dump($data);
}
public function supply_redirect(Request $request)
{
$data = $request->all();
//option 1
return redirect()->route('supply_status', compact('data')); // "Array to string conversion" error
//option 2
return redirect()->route('supply_status', ['data' => $data]); // "Array to string conversion" error
//option 3
return redirect()->route('supply_status')->with('data', $data); // Missing required parameters for [Route: supply_status] [URI: supply_status/{data}].
//option 4
return redirect()->action('TestController@supply_status')->with('data', $data); // Missing required parameters for [Route: supply_status] [URI: supply_status/{data}].
}
Route
Route::get('supply_status/{data}', 'TestController@supply_status')->name('supply_status');
For this situation you really should use the Session class
Session::put('customer_data', $request->all());
Session::save();
redirect()->route('foobar');
in foobar
if($data = Session::get('customer_data')) {
dump($data);
}
You could alternatively also do: redirect()->with(['customer_data' => $request->all()])
and then fetch it the same way with Session::get('customer_data')
or session()->get('customer_data')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With