It's possible that the issue is related to the use of the env() function in your code. When you run php artisan config:cache, Laravel will cache your configuration files, including your .env file. This means that any calls to env() will be reading from the cached configuration files, rather than the .env file directly. If you're relying on env() to read values from your .env file, this could be causing the issue you're seeing.
To fix this, you can update your code to use the config() function instead of env(). The config() function will read values from the cached configuration files, so it will work correctly even when you've run php artisan config:cache.
For example, instead of using env('APP_DEBUG'), you could use config('app.debug'). This will read the debug value from your config/app.php file, which is where the APP_DEBUG value is stored.
If you make this change and still have issues with php artisan config:cache, you may want to try updating to the latest version of Laravel to see if that resolves the issue. You could also try clearing your cache manually by deleting the bootstrap/cache/config.php file, rather than using php artisan config:clear.
Here's an example of how you could update your code to use config() instead of env():
// Before
if (env('APP_DEBUG')) {
// Do something
}
// After
if (config('app.debug')) {
// Do something
}