environment-variableslaravel-9

Laravel 9 use base_path() in .env file variable


There is a special string pattern to use base_path() into .env file variable ?

Something like : MY_PATH=%basePath%/my/path


Solution

  • You can use any external environment variables in the .env.

    For example, you could set BASE_PATH in a shell call:

    BASE_PATH=/Users/home php artisan my:command
    

    Then you simply use them in the .env e.g.

    MY_FILE="${BASE_PATH}/files/something.txt"
    

    I think you can also assign environment variables in your web server.