Creating an entry in the config/app.php
'myVar' => [
'key' => 'value'
],
and accesing it via config('app.myVar')
- Put it in a helper file and access using that helper file
check out this answer https://stackoverflow.com/a/32772686/5808894
- Using AppServiceProvider
In your app/providers/AppServiceProvider.php
in the boot
method add this, make sure to import App use App
in AppServiceProvider
public function boot()
{
App::singleton('myVar', function(){
return [
'key' => 'value'
];
});
}
and access the variable in your controller using app('myVar');
Reference https://stackoverflow.com/a/25190686/5808894