config() does not return what was configured

Asked

Viewed 44 times

2

I have a class Foobar.php that in it have a return [] with some items that are pointed out from .env, in this format:

Foobar.php:

function decode_ifnot_null() {} ... // método que auxilia na obtenção de valores de arquivos

return [
    "CONFIG_A" => env("CONFIG_A", true),
    "CONFIG_B" => decode_ifnot_null(env("CONFIG_B")),
    "CONFIG_C" => env("CONFIG_C", true),
];

In my .env, is like this:

CONFIG_A=the quick fox
CONFIG_B=C:\\users\\admin\\arquivo.json
CONFIG_C=jumps over the lazy dog

But when I call the method config("CONFIG_A"), I get a null. When I call the env("CONFIG_A"), i get the quick fox.

The archive Foobar.php is inside /config/.

What am I doing wrong?

1 answer

4


I’m rusty from Laravel, but as far as I can remember the "parameter" of the function config() should refer to the filename separated by a dot to get a specific value, for example, your file is called Foobar.php, so this should be used like this:

$variavel = config('Foobar.CONFIG_A');

To catch the other:

$variavel = config('Foobar.CONFIG_B');

If your file was called cyberpotato.php, it should be called cyberpotato.php:

config('cyberpotato.CONFIG_B');

If you want to take the whole array, it should be:

var_dump(config('cyberpotato'));
  • 1

    You love misspelling my name. Thanks anyway!

  • 1

    @Cypherpotato Cyberpotato is your pet BOT :)

  • Considerable haha

Browser other questions tagged

You are not signed in. Login or sign up in order to post.