Home save collection in global variable in laravel 5.6
Reply: 0

save collection in global variable in laravel 5.6

user4386 Published in September 19, 2018, 11:03 am

so basically i have an index page where i have to go to controller to fetch data from database


route::get('/index/{$x}', 'indexController@index');

index controller:-

$data = Data::where('name', $x)->get(); return View::make('index', compact('data');

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


route::get('/second', indexController@second);});

Second Controller:-

$data = $data->sortBy('id'); return View::make('second', compact('data');

i thought of saving data in global variable in controller

so i added private variable inside controller and try to access it through $this->data

but it did not work cause based on my search the controller will be closed after it returns view

so if i try access $this->data inside second function it will be empty

is it possible to save queried data (collection) in global variable

as i do not want to query same data for every page

your help will be appreciated

share|improve this question

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333252 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO