Search code examples
phplaravel-5.5laravel-artisan

Laravel artisan route:cache throw error Constant XXX already defined


Env

  • Laravel 5.5

Issue

When I run:

php artisan route:cache

It throws error:

In app.php line 3:

Constant XXX already defined

in my config/app.php, I defined some global constants, such as:

define("XXX", "xxx");

If I removed them, no error thrown anymore.

Question

I wonder if I want to keep those constants in config files, is there any way to avoid this problem?


Solution

  • You can not do this in such way. If you want to add any new item in config/app.php, just try this way:

    1. in config/app.php file, Add 'XXX' => 'xxx'.

    2.When you want to call this variable, use it config('app.XXX')