Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Db Config Laravel Package

inerba/filament-db-config

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require inerba/filament-db-config
    

    Publish the migration and config:

    php artisan vendor:publish --provider="Inerba\FilamentDbConfig\FilamentDbConfigServiceProvider" --tag="migrations"
    php artisan vendor:publish --provider="Inerba\FilamentDbConfig\FilamentDbConfigServiceProvider" --tag="config"
    

    Run migrations:

    php artisan migrate
    
  2. Register Plugin Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \Inerba\FilamentDbConfig\FilamentDbConfigPlugin::make(),
            ]);
    }
    
  3. First Use Case Define a config group in config/filament-db-config.php:

    'groups' => [
        'app_settings' => [
            'label' => 'App Settings',
            'fields' => [
                [
                    'name' => 'site_name',
                    'label' => 'Site Name',
                    'type' => 'text',
                ],
                [
                    'name' => 'maintenance_mode',
                    'label' => 'Maintenance Mode',
                    'type' => 'boolean',
                ],
            ],
        ],
    ],
    

    Access values in code:

    $siteName = config('filament-db-config.app_settings.site_name');
    

Implementation Patterns

Core Workflows

  1. Config Management

    • Dynamic Groups: Create modular config groups (e.g., payment_gateways, email_templates) by extending the config array.
    • Field Types: Leverage Filament’s field types (e.g., rich-editor, select, repeater) for complex configurations.
      'fields' => [
          [
              'name' => 'social_media',
              'label' => 'Social Links',
              'type' => 'repeater',
              'fields' => [
                  ['name' => 'platform', 'type' => 'select', 'options' => ['twitter', 'facebook']],
                  ['name' => 'url', 'type' => 'url'],
              ],
          ],
      ],
      
  2. Caching

    • Enable caching for performance-critical configs:
      'cache' => [
          'enabled' => true,
          'ttl' => 60, // Cache TTL in minutes
      ],
      
    • Clear cache manually or via events (e.g., ConfigUpdated).
  3. Page Generation

    • Auto-generate admin pages for each group:
      \Inerba\FilamentDbConfig\FilamentDbConfig::generatePages();
      
    • Customize pages by extending FilamentDbConfigPage:
      use Inerba\FilamentDbConfig\Pages\FilamentDbConfigPage;
      
      class CustomConfigPage extends FilamentDbConfigPage
      {
          protected static string $group = 'app_settings';
          protected static string $navigationIcon = 'heroicon-o-cog';
      }
      
  4. Integration with Filament Forms/Tables

    • Use FilamentDbConfig in forms:
      use Inerba\FilamentDbConfig\Facades\FilamentDbConfig;
      
      $form->components([
          FilamentDbConfig::make('app_settings.site_name')
              ->label('Configure Site Name'),
      ]);
      

Advanced Patterns

  1. Environment-Specific Configs

    • Override configs per environment using config/filament-db-config.php:
      'environments' => [
          'local' => [
              'app_settings' => [
                  'debug_mode' => true,
              ],
          ],
      ],
      
  2. Validation Rules

    • Add validation to fields via config:
      'fields' => [
          [
              'name' => 'max_upload_size',
              'type' => 'number',
              'validation' => 'required|min:1|max:50',
          ],
      ],
      
  3. Event Listeners

    • Listen for config updates (e.g., restart queues):
      FilamentDbConfig::listen('config.updated', function ($group, $key) {
          if ($group === 'app_settings' && $key === 'queue_restart') {
              Artisan::call('queue:restart');
          }
      });
      
  4. Multi-Tenant Support

    • Scope configs to tenants by extending the Config model:
      class TenantConfig extends \Inerba\FilamentDbConfig\Models\Config
      {
          public function tenant()
          {
              return $this->belongsTo(Tenant::class);
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Cache Invalidation

    • Issue: Stale cached values after updates.
    • Fix: Clear cache manually or use the ConfigUpdated event:
      FilamentDbConfig::clearCache('app_settings');
      
    • Tip: Disable caching during development ('cache.enabled' => false).
  2. Field Type Mismatches

    • Issue: Config values not matching expected types (e.g., boolean stored as string).
    • Fix: Use casts in the Config model or validate on retrieval:
      $value = FilamentDbConfig::get('app_settings.maintenance_mode', false);
      
  3. Migration Conflicts

    • Issue: Custom Config model migrations may conflict.
    • Fix: Publish and modify migrations carefully:
      php artisan vendor:publish --tag="filament-db-config-migrations"
      
  4. Permission Handling

    • Issue: Unauthorized access to config pages.
    • Fix: Use Filament’s built-in policies or middleware:
      \Inerba\FilamentDbConfig\FilamentDbConfigPlugin::make()
          ->middleware([\Spatie\Permission\Middlewares\PermissionsMiddleware::class]),
      

Debugging Tips

  1. Log Config Updates

    • Enable debug logging in config/filament-db-config.php:
      'debug' => [
          'log_updates' => true,
      ],
      
    • Check logs at storage/logs/laravel.log.
  2. Validate Config Structure

    • Use Artisan command to validate configs:
      php artisan filament-db-config:validate
      
  3. Inspect Database

    • Verify data in filament_db_configs table:
      SELECT * FROM filament_db_configs WHERE group_name = 'app_settings';
      

Extension Points

  1. Custom Field Types

    • Extend FilamentDbConfigField to add custom fields:
      class CustomField extends FilamentDbConfigField
      {
          protected static string $type = 'custom_field';
      
          public static function make(): static
          {
              return new static();
          }
      }
      
  2. Override Default Behavior

    • Replace the Config model or repository:
      FilamentDbConfig::setConfigModel(CustomConfigModel::class);
      
  3. Add Custom Actions

    • Extend the FilamentDbConfigPage to add bulk actions:
      use Inerba\FilamentDbConfig\Pages\FilamentDbConfigPage;
      
      class ExtendedConfigPage extends FilamentDbConfigPage
      {
          public static function getActions(): array
          {
              return [
                  Tables\Actions\Action::make('export')
                      ->action(fn () => Export::download(...)),
              ];
          }
      }
      
  4. Localization

    • Override labels/placeholders via language files:
      // resources/lang/en/filament-db-config.php
      return [
          'app_settings' => [
              'site_name' => [
                  'label' => 'Custom Site Name Label',
              ],
          ],
      ];
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware