One solution is to use Laravel's global helper function config(). You can define your variables in a configuration file and then access them from any controller using config(). Here's an example:
- Create a new configuration file in the
configdirectory, e.g.myconfig.php. - Define your variables in the configuration file, e.g.:
return [
'my_variable' => 'my_value',
'another_variable' => 'another_value',
];
- In your controller, you can access the variables using
config():
$myVariable = config('myconfig.my_variable');
$anotherVariable = config('myconfig.another_variable');
Note that you can also use the config() function to set values dynamically, e.g.:
config(['myconfig.my_variable' => 'new_value']);
This will update the value of my_variable in the configuration file.