[英]how to access variable from config file in laravel
I have one file inside config folder lets say: file1
我在 config 文件夹中有一个文件可以说:
file1
File Location:
config/
---file1.php
I have following code in my file: file1.php
我的文件中有以下代码:
file1.php
return [
'MASTER_KEY' => ['SUB_KEY1' => 'SOME_VALUE', 'SUB_KEY2' => 'SOME_VALUE', 'SUB_KEY3' => 'SOME_VALUE'],
];
How to access the value from MASTER_KEY
of particular SUB_KEY
?如何访问从价值
MASTER_KEY
特定的SUB_KEY
?
In order to access that value you have 2 choices which are the same at the end:为了访问该值,您在最后有 2 个相同的选择:
first one: which use Config
refers to the config facade.第一个:其中
use Config
是指配置门面。
use Config;
$myValue = Config::get('file1.MASTER_KEY.SUB_KEY1');
enter code here
second one: using config()
helper function which uses Config
facade and its only an alternative and easy way to use Config
facade.第二个:使用
config()
它使用辅助功能Config
的立面和其仅使用一个替代的和容易的方式Config
外观。
$myValue = config('file1.MASTER_KEY.SUB_KEY1');
Make a use Config;做一个使用Config; in your controller.
在您的控制器中。 In config/file1.php
在 config/file1.php
<?php return [
'ADMIN_NAME' => 'administrator',
'EMP_IMG_PATH' => '../uploads/profile/original',
'EMP_DOC_PATH' => '../uploads/profile/documents', ];
In controller在控制器中
use Config;
$variable= Config::get('file1.EMP_DOC_PATH');
By this way you can get the variables value from config.通过这种方式,您可以从配置中获取变量值。 I think this will make something good.
我认为这会有所作为。
use用
config('file1.keyname');
if you have made any changes in config file then it might not work .如果您对配置文件进行了任何更改,则它可能无法正常工作。 so after changes in config file you have to run the following two commands .
所以在配置文件更改后,您必须运行以下两个命令。
php artisan config:cache
php artisan config:clear
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.