0

I have an admins array as a variable which is now declared in ViewComposer. However, now I want to use the same variable in middlewares too. Where is the best way to place a variable so I can share it through other files?

What I mean by ViewComposers:

$admins = ['hello@example.com'];

Where should I define it so that I can access it both in Middleware and ViewComposer? Or maybe completely globally through the app?

(If it was a string, I'd use .env but it doesn't accept arrays)

senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

2

You can use configuration-values

$value = config('admins.list');// change admins and list is the key array returned

To set configuration values at runtime, pass an array to the config helper:

config(['admins.list' => [ 'admis list' ] ]);

admins would be inside config folder as admins.php

admins.php is something like following

return [
   'list' => [
       'admin1',
       'admin2'
   ],
   'other settings' => true
];
Hakan SONMEZ
  • 2,176
  • 2
  • 21
  • 32
freelancer
  • 1,174
  • 5
  • 12