laravel 配置文件
You discover that storing files on your own server is extra load, so not ideal. You open your web browser and do a google search on "efficient ways to store files". Finally, you decide to use Amazon S3. Since you are a Laravel user, you open config/filesystems.php
, and then you change the default key value from local
to s3
, fill in your API keys. Just like that, you have your files uploaded to Amazon S3.
您会发现将文件存储在自己的服务器上是额外的负担,因此并不理想。 您打开网络浏览器,然后在Google上搜索“有效的文件存储方式”。 最后,您决定使用Amazon S3。 由于您是Laravel用户,因此请打开config/filesystems.php
,然后将默认密钥值从local
更改为s3
,并填写API密钥。 这样,您就可以将文件上传到Amazon S3。
Magic, no. This is an example of a configurable system, and an example of SOLID programming. By setting some array values in a file, we can get a system to work without breaking anything. This article is not about SOLID, we are here to talk about Laravel configuration files and how to use them.
魔术,不。 这是可配置系统的示例,也是SOLID编程的示例。 通过在文件中设置一些数组值,我们可以使系统正常运行而不会破坏任何内容。 本文不是关于SOLID的,我们在这里谈论Laravel配置文件以及如何使用它们。
Configuration files in Laravel provide an easy way to set options required by parts of our application to work. Laravel has a lot of configuration files in the config
directory. We as developers also have the option to create our own configuration file(s).
Laravel中的配置文件提供了一种简单的方法来设置应用程序某些部分正常工作所需的选项。 Laravel在config
目录中有很多配置文件。 作为开发人员,我们还可以选择创建自己的配置文件。
何时使用配置文件 ( When to use Config file )
When building a Laravel Package, config files go a long way in helping you build a configurable and functional package.
在构建Laravel软件包时,配置文件在帮助您构建可配置和功能性软件包方面大有帮助。
创建配置文件 ( Creating a Configuration File )
One reason developers love Laravel is the fact that it makes everything simple. Creating configuration files is not an exception to that rule. To create a configuration file, go to the config
directory and create a file there. For our example, let's call our file social.php
. After creating the file, open it and return an empty array. There, we have created a configuration file.
开发人员喜欢Laravel的原因之一是它使一切变得简单。 创建配置文件不是该规则的例外。 要创建配置文件,请转到config
目录并在其中创建文件。 对于我们的示例,我们将文件social.php
。 创建文件后,将其打开并返回一个空数组。 在那里,我们创建了一个配置文件。
return [];