Laravel’s .env file is included to use, so it’s easy to have a different configuration based on the environment your app is running on. This gives you the flexibility to have different variables for local, staging, production, and even different developers’ machines.
Typically these files are small and manageable, but there are times when you run into situations where you duplicate the same data within the file. Here is an example:
The dotenv package that Laravel relies on can use variables with other defined variables in this same file. For example:
Granted this file isn’t usually crazy long or complicated, but this simple trick allows you not to repeat yourself and can be useful when you have multiple services requiring the same piece of data.
Many thanks to Caleb Porzio for pointing out the ability to do this.
Join the weekly newsletter and never miss out on new tips, tutorials, and more.
- Software Engineer Lead (PHP)
- Full-time Senior Web Developer
Wayne State University
- Senior Software Engineer
- Full Stack Engineer
Remote or Medford, Oregon
- Laravel Developer (fulltime - Dutch only)
Qbixx | Webservices
- Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
- Senior Quality Assurance Engineer
Laravel Package To Login As Other Users During Development
For websites with advanced ACL functionality, developers often find themselves manually logging in as a different use…
Ubuntu Server DNS Resolver Issues
This morning many people, including Laravel News, are experiencing that their sites are erroring when communicating w…