Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoshP's avatar
Level 7

How to maintain form input and object property between controller calls? (Report generation)

I can get into code if necessary, but I'm first interested in just how this might normally be done... at a high level.

The quick overview:

I'm building a reporting engine.

There are a few available reports, user clicks on one and goes to a report options page. This is just a small form with, for instance, a date range picker.

The submit button on that options page hits the controller method to generate and return the html view of the report.

On that view, there is a back button, as well as export buttons for pdf, excel, etc.

My two questions are basically this:

1 - How do I get the back button to behave like the browser's back button. I.e., I'd like the form to pre-populate with the previous values.

2 - If I click the pdf export button for instance, how does the controller method that request hits get access to the already generated report.

What I've tried:

1 - I've tried using the session()->flash() and ->reflash() to no avail. Not really sure where I'm failing there. Also dipped a toe into using the cache functionality (db driver).

2 - In my ReportsController@generate method, I'm doing this: $this->report = $report->getDompdf()->outputHtml(); So the controller itself has the report. How do I get at this from the subsequent method call in this controller?

One of the complicating bits is that I've done my best to create my reportOptions, reportView and generate methods report-agnostic. The same methods will be used for all my reports, so I can't just grab the specific form inputs out of the request.

Any insight would be much appreciated. Thanks!

0 likes
2 replies
jlrdw's avatar

You might use a custom session array, or just session.

https://laracasts.com/discuss/channels/guides/session-array-usage

But it can get complex if there were checkboxes, dropdowns, etc. You will have to play around some (trial and error) to tweak what you are after.

Cache might work, read up on caching. I am not sure about cache if a real busy site.

If the form was already submitted, you could simply reload that data much like you'd load an edit page.

Other way pass a data array or json data as you go. I'd try session first.

Just me, but for complex reports I write a one pager:

https://drive.google.com/file/d/1R3VtCPpQ0JP3q7dpjt4M69eYFLPenMU_/view?usp=sharing

In other words (skip mvc).

Also there is https://github.com/PHPJasper/phpjasper

JoshP's avatar
Level 7

@JLRDW - Thanks for the link. Nice write up! I'll see if I can get something like that rolling.

Please or to participate in this conversation.