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

后端 未结 11 741
猫巷女王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:11

    First you make Constants folder inside your app directory.

    And then you make Constants.php. Define your constants in this file

    For Example :

    define('ONE', '1');
    define('TWO', '2');
    

    And you modify the composer.json

    Alternatively, you can use composer.json to load the bootstrap/constants.php file by adding the following code to the “autoload” section, like so:

    "autoload": {
        "files": [
            "bootstrap/constants.php"
        ]
    }
    

    And update your composer !

提交回复
热议问题