Laravel Configuration Steps

In Laravel we use .env file for environment variables which provide a list of web services to the application.

.env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:O9euR3Y4hiHoSpu0auICnsj7cQtEeZ9g2uT9a+/SXbs=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

How to Retrieve Environment Variables

All the environment variables are declared in the .env file and we can be accessed environment variables by using env-helper functions (inside app.php).

These environment variables are listed into $_ENV global. We can access these variable as below :

 ‘name’ => env(‘APP_NAME’, ‘Laravel’),

How to Access Configuration Values

For access the configuration values in the application you must use global config helper function.

It returns default values if the configuration values are not initialized.

In case if the configuration values are not initialized, default values are returned.

Leave a Reply

Your email address will not be published. Required fields are marked *