1

Currently, I have an environment variable in my .env file.

MY_NAME_TEST=Testing

How do I pass that variable as part of a path in a config file? I'm trying to get a path similar to below:

base_path('Plugins/Testing/Database/Migrations/')

Notice the "Testing" part of the path in the sample above; I need that name to be different each time.

miken32
  • 42,008
  • 16
  • 111
  • 154
Jazzman
  • 85
  • 1
  • 8

1 Answers1

2

You're able to retreive the values anywhere in your laravel project by making use of the env function.

env('MY_NAME_TEST'); // returns "Testing"

In your case it would be used like so:

base_path('Plugins/' . env('MY_NAME_TEST') . '/Database/Migrations/'

The second parameter the env function takes is a default value if a value is not already set.

Linus Juhlin
  • 1,175
  • 10
  • 31