官术网_书友最值得收藏!

Using .env for your local build

This was one of the best changes to Laravel from version 4 and 5 in my opinion. When I was doing Ruby on Rails work, it also had this feature, and this is the key to help create an application that falls in the Twelve Factor App workflow. You will learn how to use this file for setting keys to some recipes later on in the book. In this example, we will start using it to set up our database.

For the rest of this book, I will use PHPStorm for my editor, which helped me a ton to explore Laravel and PHP code when I first started. Make sure your editor has plugins to easily click and explore classes.

Getting ready

When you installed Laravel, it copied the .env file into place. So, just open your editor of choice and open the application directory.

How to do it...

  1. Open .env in your editor.
  2. Alter the file as follows, so the database name and the URL match what we would put in our Homestead setup file:

How it works...

First of all, this is a hidden file. The . in front of it makes it hard to see in File Managers and even the command line. When at the command line, ls -a * is how to show this hidden file. Most code editors or IDEs will show you these.

Also note that Laravel comes with a .gitignore file that includes this file:

We will have to consider the addition or changes of any settings in env, as we push this application to Production for everyone to see when we are done. I will cover this more in Chapter 10, Deploying Your App.

So, what did we change in this file? Most of what you see was already there; we just set two things:

  • DB_DATABASE=recipes_local
  • APP_URL=https://recipes.dev

This is it, really! If you look back, this is what we set in the Homestead.yml file. You can see what we called the database and domain name. So now we need to tell our application what database table to use and which Homestead is made for us. Yeah, for Homestead!

See also

主站蜘蛛池模板: 扬州市| 溧水县| 皋兰县| 湖口县| 桐柏县| 台州市| 杭州市| 依安县| 阿图什市| 桂林市| 都江堰市| 宁晋县| 清水县| 塘沽区| 尉犁县| 丹巴县| 隆回县| 溧水县| 定西市| 金堂县| 郴州市| 清苑县| 比如县| 监利县| 吉木乃县| 宜丰县| 霍林郭勒市| 五常市| 田阳县| 曲水县| 泰顺县| 襄垣县| 丽江市| 大兴区| 潼南县| 张家口市| 惠水县| 互助| 五寨县| 隆安县| 涟源市|