What is the best practice for adding constants in laravel? (Long List)

后端 未结 11 870
猫巷女王i
猫巷女王i 2021-01-30 06:21

I am rather new to laravel. I have a basic question, What is the best way to add constants in laravel. I know the .env method that we use to add the constants. Also I have mad

11条回答
  •  一整个雨季
    2021-01-30 07:08

    For most constants used globally across the application, storing them in config files is sufficient. It is also pretty simple

    Create a new file in the config directory. Let's call it constants.php

    In there you have to return an array of config values.

    return [
        'options' => [
            'option_attachment' => '13',
            'option_email' => '14',
            'option_monetery' => '15',
            'option_ratings' => '16',
            'option_textarea' => '17',
        ]
    ];
    

    And you can access them as follows

    Config::get('constants.options');
    // or if you want a specific one
    Config::get('constants.options.option_attachment');
    

提交回复
热议问题