PHP code example of jomigomes / laravel-settings

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

    

jomigomes / laravel-settings example snippets


use JomiGomes\LaravelSettings\Models\Setting;

return [
    'system' => [
        'features' => [
            'enable_notifications' => [
                'value' => true,
                'type' => Setting::TYPE_BOOLEAN,
            ],
        ],
    ],
    
    'user' => [
        'preferences' => [
            'theme' => [
                'value' => 'light',
                'type' => Setting::TYPE_STRING,
            ],
        ],
    ],
];

use JomiGomes\LaravelSettings\Facades\Settings;
// Or use the model directly:
// use JomiGomes\LaravelSettings\Models\Setting;

// Get a setting
$setting = Settings::get('features.enable_notifications', 'system');

// Set a setting
Settings::set('features.enable_notifications', false, 'system');

// Get all settings for a scope
$allSettings = Settings::getAllScoped('system');

// Get filtered settings
$features = Settings::getFiltered('system', 'features');

use JomiGomes\LaravelSettings\Traits\HasSettings;

class User extends Model
{
    use HasSettings;
}

$user = User::find(1);

// Get a setting
$theme = $user->getSetting('preferences.theme');

// Set a setting
$user->setSetting('preferences.theme', 'dark');

// Get all settings
$allSettings = $user->getAllSettings();

// Get filtered settings
$preferences = $user->getFilteredSettings('preferences');

use JomiGomes\LaravelSettings\Events\SettingUpdated;

protected $listen = [
    SettingUpdated::class => [
        LogSettingChange::class,
    ],
];

'cache' => [
    'enabled' => true,
    'ttl' => 3600, // seconds
],
bash
php artisan vendor:publish --tag=settings-config
bash
php artisan vendor:publish --tag=settings-migrations
php artisan migrate