Perhaps cache the results. Or put that query in a class you can call when needed.
Reuse Data from a Controller in an other View
Hi,
I am new at this and need a little help.
I have a view that contains data in a sidebar. The view has a controller and the information in that sidebar is populated from a query in that controller. I now want to create other views each with their own controller but keep that sidebar. I was thinking of using a partial but I didn't know if that would work or if I could create a controller just for a partial or if either was a best practice. I didn't want to just repeat the query in each controller.
Each below is a query I need to use in the other controllers:
return view( 'ResearchReports.ResearchDatabase.explore.explore_maps' )
->with( 'site', $site )
->with( 'studyUnits', $studyUnits )
->with( 'selectStructures', $selectStructures )
->with( 'excavations', $excavations );
I have an ID in the URL that is needed for each of these queries.
I basically want to reuse that query in multiple controllers so I can populate that sidebar for all the other views without copy/paste the query in each controller..
Thanks, Stan
@tykus Yes. Exactly the same data in a number of views. It is general information that I want available in a number of views with text and links. I created a Service Class, placed all my queries in there and used that.
Please or to participate in this conversation.