Home > Article > PHP Framework > What does the laravel config() method do?
In laravel, the function of the config() method is to obtain the data defined in the config configuration directory, the syntax is "config('key')"; the key value can be spliced through the "." syntax, which contains the required The file name to be accessed and the option name, such as "config('app.url')".
The operating environment of this tutorial: Windows 7 system, Laravel version 5, Dell G3 computer.
Laravel's config directory generally stores configuration information, such as app.php, auth.php, mail.php, view.php, etc.
config directory structure
The default directory structure is:
Specified data can be obtained through the config('key') method.
The setting value can be read through "dot" syntax, which contains the file name to be accessed and the option name.
Now I want to read the url of the \config\app.php
file. The data in the file is:
'url' => 'http://localhost',
How to get it:
config('app.url')
If you find If app.url is not reached, the second parameter will be returned by default.
config('app.url', 'default_val')
Related recommendations: The latest five Laravel video tutorials
The above is the detailed content of What does the laravel config() method do?. For more information, please follow other related articles on the PHP Chinese website!