PHP code example of emadha / laravel-dynamic-config

1. Go to this page and download the library: Download emadha/laravel-dynamic-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/ */

    

emadha / laravel-dynamic-config example snippets


# /config/app.php 
return [
    'dynamic' => true,
     ...
];


return [
    /* The Config database table name */
    'table'                   => 'confs',

    /*
     * The key that defines which config file should be loaded dynamically
     * and store into the database
     * Add that key to any config file to make it dynamic.
     */
    'dynamic_key'             => 'dynamics',

    /*
     * they key which will have the defaults of a config key
     * example: config('defaults.app.name'); This is added on runtime.
     */
    'defaults_key'            => 'defaults',

    /*
     * Delete orphan keys
     * if set to true and delete a key from the actual config file,
     * that key will be deleted from database.
     */
    'auto_delete_orphan_keys' => true,
];

dd(config('app.name')); // Will return a Model object for that db row (key)
echo config('app.name'); // Will get the value from a config key using __toString() method from the DynamicConfig Model;
config('app.name')->setTo('Some New Value'); // will update that config key in database
config('app.name')->default(); // Will return the default value of that key (from the actual config file and not from the database)
config('app.name')->revert(); // Will revert the key value in database back to default (to what it is in the actual config file) 

# /config/site.php
return [
    'dynamic'=>true,
    'title'=>config('app.name'),
    'description'=>'My Site Meta Description',
    'google'=>[
        'UA'=>'UA-XXXXXXXX-X',
        'enabled'=>true,
    ],
];
 bash
php artisan vendor:publish --provider="EmadHa\DynamicConfig\ServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="EmadHa\DynamicConfig\ServiceProvider" --tag="migrations"
blade
{{-- welcome.blade.php--}}
<title>{{ config('site.title') }}</title>
<script>// Analytics ID: {{ config('site.google.UA')}}</script>