Do Laravel-friendly modifications to the. env configuration file need to be modified by modifying the code each time ?. Can the env file be configured in the background?
Actually, it is easy to implement. add the following functions to your project.
function modifyEnv(array $data){ $envPath = base_path() . DIRECTORY_SEPARATOR . '.env'; $contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES)); $contentArray->transform(function ($item) use ($data){ foreach ($data as $key => $value){ if(str_contains($item, $key)){ return $key . '=' . $value; } } return $item; }); $content = implode($contentArray->toArray(), "\n"); \File::put($envPath, $content);}Use
// You can update any value you want key => value $ data = ['app _ env' => 'Your _ environment ', 'app _ key' => 'Your _ key', 'app _ debug' => 'trueorfalse', 'DB _ database' => 'test ', 'db _ username' => 'test', 'DB _ password' => 'test', 'DB _ host' => 'localhost ', 'cache _ DRIVER '=> 'File', 'session _ DRIVER' => 'File',]; // or $ data = ['DB _ host' => '127. 0.0.1 ',]; // use the function to update modifyEnv ($ data );
Is it easy? in this way, you can configure the Laravel. env file in a graphical way in the background ~
Welcome to join the group for discussion: 365969825