DEV Community

techdurjoy
techdurjoy

Posted on

How to Update .env File in Laravel Programmatically

There may be times when you want to dynamically change your .env file on the fly. This could be an admin functionality or perhaps you are creating an install script and want to be able to dynamically update the database data in your .env file.

It's actually pretty simple, just use this function to pass in the $key, $value that you want to change and it will dynamically update your environment variables.

How to Update .env File in Laravel Programmatically

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more