Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 create array variable in .env file for global use

Actually, I want an array like this in .env file. I do not have any idea to create an array variable in .env file.

 VARIABLE_NAME = [
    [0] => 'Value 1',
    [1] => 'Value 2',
    [2] => 'Value 3',
    ................

];
like image 704
Keval Garala Avatar asked Aug 17 '15 09:08

Keval Garala


1 Answers

You can't store an array in .env file as the ENV format doesn't support that.

A workaround could be serializing the array to a string of some known format, e.g. comma separated values, and then split it whenever you needed.

This should do the trick:

#.env file
VARIABLE_NAME="Value 1,Value 2,Value 3"

#config/app.php
return [
  'VARIABLE_NAME' => explode(',', env('VARIABLE_NAME'))
];
like image 176
jedrzej.kurylo Avatar answered Nov 08 '22 21:11

jedrzej.kurylo