PHP code example of danielemontecchi / laravel-scoped-settings

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

    

danielemontecchi / laravel-scoped-settings example snippets


// Global settings
setting()->set('site.name', 'My App');
$siteName = setting()->get('site.name');

// Set with optional caching (global or scoped)
setting()->set('site.name', 'My App', 3600); // Cache for 1 hour

// If TTL is omitted, uses default from config (or disables cache)
setting()->set('site.name', 'My App'); // No cache if config is null

// Check if a setting exists (ignores fallback)
if (setting()->has('site.name')) {
    // the value is explicitly set
}

// Scoped settings (e.g. per user)
setting()->for($user)->set('dashboard.layout', 'compact');
$layout = setting()->for($user)->get('dashboard.layout');

setting()->all(); // ['site.name' => 'My App']
setting()->for($user)->group('dashboard'); // ['layout' => 'compact']

setting()->forget('site.name');
bash
php artisan vendor:publish --tag="laravel-scoped-settings-config"
bash
php artisan vendor:publish --tag="laravel-scoped-settings-migrations"
php artisan migrate