How to configure Laravel
This article mainly introduces "how to configure Laravel". In daily operation, I believe many people have doubts about how to configure Laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to configure Laravel"! Next, please follow the editor to study!
When you need to access configuration items at run time, you can use the Config class:
Get the value of a configuration item * *
The copy code is as follows:
Config::get ('app.timezone')
If the configuration item does not exist, you can also specify the default value returned:
The copy code is as follows:
$timezone = Config::get ('app.timezone',' UTC')
Assign a value to a configuration item
Note that the "dot" syntax can be used to access the values of configuration items in different files. You can also assign values to configuration items at run time. :
The copy code is as follows:
Config::set ('database.default',' sqlite')
The configuration value set while the program is running is only valid in this request and will not affect future requests.
Environment configuration
It is usually useful for applications to determine the values of different configuration items based on different operating environments. For example, you may want to use a different cache driver (cache driver) on the development machine and the production machine. This can be easily achieved by changing the configuration according to the environment.
Create a directory under the config directory with the same name as your environment, such as local. Then, create configuration files that contain the configuration options you want to override. For example, to override the cache driver (cache driver) in the local environment, you can create a cache.php file in the app/config/local directory and contain the following:
The copy code is as follows: