4 months ago

Making my class instance persistent over next request

Posted 4 months ago by rahul95


I'm currently working on an app where I want the current instance of one of my class/controller to be available over the next request. The actual scenario is, I'm creating a view file based on two to three chained API calls which reside in separate methods in my controller and actually assigning the API responses to the class properties as I need those to make my next call. After three chained method calls, I'm actually generating a view and the next API call must be done through an ajax request from the view and is called to the same controller. What I want to achieve is, I want to access the class properties I initialized (and may be modified) while generating my view, from the method I'm calling now.

As the ajax request loads the Controller all over again I will supposedly lose the instance, but is there any way I can achieve this, I found topics on binding singletons and instances o the ServiceProvider but I'm too confused with the official docs.

(Note: I want to achieve it this way, because I don't wanna expose my property values to the user interface and I'm not a big fan of storing these inside sessions as well.)

It'll be great if anybody can help me with this.

Please sign in or create an account to participate in this conversation.