PHP code example of paulohps / laravel-db-config

1. Go to this page and download the library: Download paulohps/laravel-db-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paulohps / laravel-db-config example snippets


// config/db-config.php
return [
    // Turn the runtime overriding on/off. When off, nothing is overridden
    // and the app falls back to the plain file-based configuration.
    'enabled' => env('DB_CONFIG_ENABLED', true),

    'table' => 'db_config_settings',
    'connection' => null,

    // Cache the stored settings so the provider does not query the database
    // on every request. 'store' = cache store (null = default), 'ttl' in
    // seconds (null = forever).
    'cache' => [
        'enabled' => env('DB_CONFIG_CACHE_ENABLED', true),
        'store' => env('DB_CONFIG_CACHE_STORE'),
        'key' => 'db-config',
        'ttl' => null,
    ],

    // Which config files (and keys) may be overridden from the database.
    'configs' => [
        '*',                                           // every file
        'app',                                         // every key of app.php
        'mail' => ['only' => ['from.address', 'from.name']],
        'services' => ['except' => ['ses.secret']],
    ],
];

use Paulohps\DbConfig\Facades\DbConfig;

// Persist a value and apply it immediately (throws KeyNotConfigurableException
// when the key is not allowed by the rules):
DbConfig::set('mail.from.address', '[email protected]');

// Read the stored (database) value, ignoring the file config:
DbConfig::get('mail.from.address');          // '[email protected]'
DbConfig::get('mail.from.name', 'fallback'); // 'fallback' (never stored)

// Remove the override — the file value is restored on the next request:
DbConfig::forget('mail.from.address');

// Check whether a key may be overridden:
DbConfig::allows('mail.from.address'); // bool

DbConfig::flushCache();   // next read repopulates
// or
DbConfig::refreshCache(); // flush and repopulate right away
bash
php artisan vendor:publish --tag=db-config-config
php artisan vendor:publish --tag=db-config-migrations