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

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

    i think best way to define constant using a helper file. check my solution.

    Define file path in composer.json

       "extra": {
            "laravel": {
                "dont-discover": []
            }
        },
        "autoload": {
            "files": [
                "app/helpers.php",
                "app/Helper/function.php"  // constant defined here
            ],
    

    app/Helper/function.php

    define("assetPath","UI/");
    define("viewPath","UI/");
    

    use this constant anywhere in project. i am using in blade file.

      
      
      
    

    my approach is better than this

    Config::get('constants.options');
    Config::get('constants.options.option_attachment');
    

    here another problem is this , you have to run cache:clear or cache command for this. but my approach not required this.

提交回复
热议问题