Home  >  Article  >  PHP Framework  >  What does the laravel config() method do?

What does the laravel config() method do?

青灯夜游
青灯夜游Original
2021-09-24 15:05:582708browse

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')".

What does the laravel config() method do?

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:

laravel config

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn