Global variable in laravel 5.7 (to access it from any Controller or class)

0

I need to save an object that simulates a database in a global variable.

I'm not interested in accessing any real database at the moment, but I'm interested in accessing that object from the different controllers to simulate my crud.

I tried to save an object in the AppServiceProvider (inside the register method):

config([ 'data' => $data]); // esta variable guarda una simulación de bbdd 

But that method is launched every time there is a request (I do not understand why) and everything is initialized.

I would like to save it in an object that allows me to store it there once and then access it in reading and writing. With what I have, I am doing:

config('data'); y config(['data'=>$data]);

... it would be worth it, if the register was not triggered in each request, initializing all the data again.

    
asked by javic3p0 30.11.2018 в 10:50
source

0 answers