I would like to take advantage of the result of a query in another function when requested
For example:
Controller
public function funcao1(Request $request){
$myObj = DB::select("SELECT * FROM myTable");
return view('myView');
}
Then I would like to use this $ myObj object in another function when it comes from my view, through a click or via ajax
Ajax
var form = $('<form action="{{ route('myRoute') }}"> method="post"'+
'<input type="hidden" name="_token" value="{{ csrf_token }}"'>
'</form>')
$('body').append(form);
form.submit();
Controller
In this part, I would like to take advantage of the object I set in the first function
public function funcao2(Request $request){
echo "<pre>";
print_r($myObj);
echo "</pre>";
}
My route would stay
Route::post('/obj', ['as' => 'myRoute', 'uses' => 'MyController@funcao2']) ;