APP_NAME=MyApp, what will config('app.name') return in a Laravel controller?<?php // .env file APP_NAME=MyApp // In a controller method return config('app.name');
The config('app.name') call returns the value set in config/app.php which uses env('APP_NAME', 'Laravel'). Since APP_NAME is set in .env as "MyApp", it returns "MyApp".
APP_DEBUG to true in your .env file. Which line is correct?Laravel treats APP_DEBUG as a boolean. Setting APP_DEBUG=1 works correctly because Laravel converts '1' to true. Other options are strings and may not convert properly.
env('MY_VAR') return null despite being set in .env?MY_VAR=hello in your .env file but env('MY_VAR') returns null in your Laravel app. What is the most likely cause?If you have cached your config with php artisan config:cache, Laravel ignores .env changes until you clear or refresh the cache. This causes env() to return null for new variables.
config('database.default') after this .env change?DB_CONNECTION=pgsql and your config/database.php uses env('DB_CONNECTION', 'mysql'), what will config('database.default') return?The config/database.php file uses env('DB_CONNECTION', 'mysql'). Since DB_CONNECTION is set to "pgsql" in .env, the config returns "pgsql".
.env files often contain sensitive information like database passwords and API keys. Committing them publicly risks exposing these secrets to unauthorized users.