Get environment value in controller

前端 未结 10 1691
既然无缘
既然无缘 2020-12-25 10:43

In my .env file I have the following:

IMAP_HOSTNAME_TEST=imap.gmail.com
IMAP_USERNAME_TEST=myemail@gmail.com
IMAP_PASSWORD_TEST=mypw

Now I

10条回答
  •  不知归路
    2020-12-25 11:22

    You can use with this format (tested on Laravel 5.5). In my case I used it for gettting the data of database connections and use on Controller:

    $User = env('DB_USERNAMEchild','');
    $Pass = env('DB_PASSWORDchild','');
    

    The second parameter can be null, or set any default in case of DB_USERNAMEchild is null.

    Your .env file can be the same:

    DB_HOST=localhost
    DB_DATABASE=FATHERBD
    DB_USERNAME=root
    DB_PASSWORD=password
    
    DB_DATABASEchild=ZTEST
    DB_USERNAMEchild=root
    DB_PASSWORDchild=passwordofchild
    

提交回复
热议问题