FULL STACK DEV
FULL STACK DEV

Reputation: 15951

change configurations of laravel on run time from database

i want to change the configurations at run time. I want to create a installer and configuration page for admin in which admin can enter the configuration Like Paypal's clients and secret keys, Stripe keys, Database connection and other API keys. Right now i m using .env file to manage the all the configurations is there a nice to way to achieve it.?

Upvotes: 2

Views: 1390

Answers (3)

Webistan
Webistan

Reputation: 357

You may use Laravel Config::set method to override config value for current request.

// app/config/project.php 
Config::set('project.secret_key', '123xxxxx');

app/config/mail.php 
Config::set('mail.username', 'new Username);

Upvotes: 0

Robin Dirksen
Robin Dirksen

Reputation: 3422

You can check if there is a file placed on the system (for example):

Routes:

if(File::exists(storage_path('/installed'))) {
    Route::get('/', function() {
        return 'installer...';
    });
} else {
    //all your routes
}

Here you can paste all your routes that will handle the setup, after that you can make the file at the storage_path('/installed') and it will show your normal routes.

Hope this works!

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163788

If you want to set config data at runtime for current request, you can use config() global helper:

config(['config.key' => 'value'])

If you want to overwrite some config data and keep it for following requests, you need to use package for this.

Upvotes: 2

Related Questions