PHP code example of subham / filament-dynamic-settings

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

    

subham / filament-dynamic-settings example snippets


// config/filament-dynamic-settings.php
return [
    'multi_tenant' => false,
    // ... other config
];

// config/filament-dynamic-settings.php
return [
    'multi_tenant' => true,
    'tenant_model' => App\Models\Tenant::class,
    'tenant_column' => 'tenant_id',
    // ... other config
];

'tabs_layout' => [
    'vertical_tab' => false,
    'contained' => true,
],

'sections_layout' => [
    'aside' => false,
    'collapsible' => false,
],

use Subham\FilamentDynamicSettings\Facades\Settings;

// Get a setting (cached, with type formatting)
$value = Settings::get('app_name', 'general', 'Default App Name');

// Get a raw setting value (no cache, no formatting)
$raw = Settings::raw('app_name', 'general', 'Default App Name');

// Set a setting value (updates existing, invalidates cache)
Settings::set('app_name', 'My Application', 'general');

// Get all settings for a module
$allGeneral = Settings::module('general');

// In multi-tenant mode (tenant ID is auto-detected)
$value = Settings::get('app_name', 'general', 'Default App Name');

// Explicitly specify tenant
$value = Settings::get('app_name', 'general', 'Default App Name', $tenantId);

// config/filament-dynamic-settings.php
'custom_components' => [
    'color_picker' => [
        'component' => YourCustomComponent::class,
        'label' => 'Label for your component',
        'description' => 'Description..',
    ],
],

namespace App\Models;

use Subham\FilamentDynamicSettings\Models\Setting as BaseSetting;

class Setting extends BaseSetting
{
    protected static function getCurrentTenantId()
    {
        if (auth()->check() && auth()->user()->currentTeam) {
            return auth()->user()->currentTeam->id;
        }
        
        return parent::getCurrentTenantId();
    }
}