1
I have an API with Laravel 5.6 and need to create global variables that throughout the application can have their value changed, but I’m having problems.
Example: 1. In the first request, the value of this variable as "test"; 2. In the second request I want to take the current value, which should be "test";
- I initially tried using config, but it didn’t work;
- I tried to use Session, but I had the same problem;
- I tried to set a variable in the "super controller", where all the controllers extend to it, it didn’t work.
The variable value is only valid during the execution of the request, that is, I make a request to the aaaControler controller, it makes use of other controllers, within the same request the value persists, but ends in the return.
I thought to persist in the database, create a reference and always search for this value there, but this will be the best way ?
I ask for help in this matter.
Thank you.
have tried using Composer?
– Alvaro Alves
Yes, you should persist the value, but not necessarily in the bank. In session it should already work, since it serves precisely for this. There are also other options, such as file persistence, memcached, redis, etc. To understand more what is happening, you should read about how the HTTP protocol is stateless. Start with What is a "stateless protocol", like HTTP?
– Woss