php - how do I pass on large datasets across different route requests - Laravel
940
Question might be unclear. here's the explanation. Let's say I've:
Route file:
Route::get('testing', '[email protected]');
Route::get('testingtwo', '[email protected]');
Controller file:
public function functionOne() {
$this->data = generateReallyBigArray();
return redirect('testingtwo');
}
public function funtionTwo() {
// Here $this->data is lost. obviously 'coz this controller file got reinstantiated for @functionTwo
return view('someview', ['data' => $this->data]);
}
$this->data
is lost the momenttestingtwo
is hit. How do I pass this data across different route requests? Or if there're other ways of doing it.
I was thinking of doing this:
public function functionOne() {
$this->data = 'somedata';
return $this->functionTwo();
}
public function funtionTwo() {
// Here $this->data is lost. obviously 'coz this controller file got reinstantiated for @functionTwo
// even this doesn't work. Exception: Method get does not exist
return Route::get('testingtwo', function() {
return view('someview', ['data' => $this->data]);
});
}
Answer
Solution:
use with() to send data through session -
Or you could flash() the data for using on next request.
Answer
Solution:
the best way for that is traits
and in your controllers write
you can use traits over controllers or You can access your controller method like this:
This will work, but it's bad in terms of code organisation (remember to use the right namespace for your ControllerName)