Laravel’s config caching (php artisan config:cache) compiles all configuration files in the /config directory into a single cache file. There is no built-in way to exclude specific config files from this process. All files in /config are included.
Workarounds:
Move the Config File Outside /config:
If you don’t want a file cached, move it outside /config (e.g., /storage or elsewhere). Then, load it manually when needed:
Load Dynamically (Not via config()):
Don’t use config('custom') for this file. Instead, load it as shown above, so it’s not part of the config cache.
Environment Variables:
If the data is simple, consider using .env variables instead.
Summary:
You cannot tell Laravel to ignore a specific file in /config during config caching. The only way is to keep that file outside /config and load it manually.
You don't do that. When Laravel constructs the config object, it either reads from the individual config files or from the cache. Doing both would negate any benefits gained from caching.
@ferid The entire point of the config:cache command is to, well, cache configuration values. So why would you intentionally want to break that behaviour?
@Glukinho Configuration files are part of the source code and shouldn't change during runtime, much less environment variables. Dynamic settings should be maintained somewhere else.
I got I was wrong with this idea. So I had admin configuration file and in that static array I had callbacks that is why couldn't cache that file properly. So I decide to move that config to app/service