Reputation: 2445
I've built a piece of software which uses Laravel config module to consume certain settings.
Thing is, we're using Laravel Forge to auto-deploy, and everytime we deploy, configs are reset to the "blank" state, thus breaking some things everytime I deploy.
I have added the files to .gitignore, but doesn't seem to do the trick.
Can anyone point me towards the right direction in order to save this config files without having the re-set them everyime we deploy?
Thanks everyone!
Upvotes: 0
Views: 188
Reputation: 1
In Laravel, store configuration files in the config
directory. Access them using the config()
helper function.
For example, config('app.timezone')
retrieves the timezone value from the app.php
config file.
Avoid hardcoding configuration values directly in your code; instead, use environment variables stored in the .env
file and reference them in your configuration files using env()
. This approach ensures better management and security of your configuration settings.
Upvotes: -1
Reputation: 7447
It would be helpful to have an example of your config and .env files
Config files for multiple environments rely on .env
files in each environment.
env()
returns either the matching variable from your .env or the value specified.
so env('QUEUE_DRIVER', 'sqs')
would look into the .env
file for the QUEUE_DRIVER
variable if it can't find a variable it returns the default 'sqs'
.
An example of a queue config file might looks like this.
config/queue.php
<?php
return [
'default' => env('QUEUE_DRIVER', 'sqs'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'sqs' => [
'driver' => 'sqs',
'key' => env('SQS_KEY'),
'secret' => env('SQS_SECRET'),
'prefix' => env('SQS_URL'),
'queue' => 'general_queue',
'region' => 'us-east-1',
],
],
];
You would then set your variables in your .env file for each environment.
Production may look like this.
.env
QUEUE_DRIVER=sqs
SQS_KEY=yoursqskey
SQS_SECRET=yoursqssecret
SQS_URL=yoursqsurl
Your local environment might look like this.
.env
QUEUE_DRIVER=sync
You can edit your .env
file in forge under Sites > Site Details > Environment
Upvotes: 2