Skip to content

Instantly share code, notes, and snippets.

@Neoglyph
Last active April 5, 2018 08:49
Show Gist options
  • Save Neoglyph/485000ef3a126b7f158e404d6a2f0ce2 to your computer and use it in GitHub Desktop.
Save Neoglyph/485000ef3a126b7f158e404d6a2f0ce2 to your computer and use it in GitHub Desktop.
Create dynamic config entries from database - Laravel (5.5/5.6)
<?php
// Laravel 5.5/5.6
// AppServiceProvider
public function boot() {
// If we have a database table with configs...
if (Schema::hasTable('table_with_config')) {
// Get all database stored configs
// DatabaseConfigs is a Model
$configs = \Cache::rememberForever('configs', function() {
return DatabaseConfigs::all();
});
// Set config for all database configs
foreach ($configs as $dbConfig) {
$config = $dbConfig->config;
// Merge the fixed config file with the database config values
if ($fixedConfig = \Config::get($dbConfig->name)) {
$config = array_merge($fixedConfig, $config);
}
\Config::set($dbConfig->name, $config);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment