Explain how the Laravel framework modifies the. Env configuration file

Source: Internet
Author: User
Using the Laravel framework to develop PHP programs, configuring the. env file for the framework is critical, and the file requires a configuration database, database users, and caching. The following article mainly introduces you how to modify Laravel. env configuration file related information, you need to refer to the friend.

Objective

Does env have to be changed by changing the code? Env files can be configured in the background? In fact, it is very simple to implement, add the following function to your project

Sample code

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::p ut ($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 ' = ' Localh ' Ost ', ' cache_driver ' = ' file ', ' session_driver ' = ' file ',];//or $data = [' db_host ' = ' 127.0.0.1 ',];//use function update m Odifyenv ($data);

How, is not very simple, so that you can configure the Laravel. env file through the background graphics ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.