title: save collection in global variable in laravel 5.6
body: <p>so basically i have an index page where i have to go to controller to fetch data from database</p>
  
  <p>route:-</p>
  
  <pre><code>route::get('/index/{$x}', 'indexController@index');
  </code></pre>
  
  <p>index controller:-</p>
  
  <p><code>$data = Data::where('name', $x)-&gt;get();
  return View::make('index', compact('data');</code></p>
  
  <p>then inside index page i have link that goes to second page 
  with same data,  i d not want to query the same data as it may affect performance</p>
  
  <p>route:-</p>
  
  <pre><code>route::get('/second', indexController@second);});
  </code></pre>
  
  <p>Second Controller:-</p>
  
  <p><code>$data = $data-&gt;sortBy('id');
  return View::make('second', compact('data');</code></p>
  
  <p>i thought of saving data in global variable in controller</p>
  
  <p>so i added private variable inside controller and try to access it through <code>$this-&gt;data</code></p>
  
  <p>but it did not work cause based on my search the controller will be closed after it returns view </p>
  
  <p>so if i try access <code>$this-&gt;data</code> inside second function it will be empty</p>
  
  <p>is it possible to save queried data (collection) in global variable</p>
  
  <p>as i do not want to query same data for every page </p>
  
  <p>your help will be appreciated</p>