8

I have one file inside config folder lets say: file1

File Location:
    config/
    ---file1.php

I have following code in my file: 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?

4 Answers 4

18

Assuming for SUB_KEY2, Try -

config('file1.MASTER_KEY.SUB_KEY2')

Guide

Sign up to request clarification or add additional context in comments.

2 Comments

I appreciate your feedback but i want to access SUBKEY value
Which SUBKEY value?
7

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

1 Comment

your comment is life saver
5

In order to access that value you have 2 choices which are the same at the end:

first one: which use Config refers to the config facade.

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.

$myValue = config('file1.MASTER_KEY.SUB_KEY1');

Comments

3

Make a use Config; in your controller. In 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.