PHP code example of inerba / filament-db-config

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

    

inerba / filament-db-config example snippets


    public function form(Form $form): Form
    {
        return $form
            ->components([
                TextInput::make('site_name')->label('Site Name'),
                TextInput::make('contact_email')->label('Contact Email'),
                Toggle::make('maintenance_mode')->label('Maintenance Mode'),
            ])
            ->statePath('data');
    }
    

        $siteName = db_config('website.site_name', 'Default Site Name');
        

'table_name' => 'db_config',

'cache' => [
    'prefix' => 'my-app-settings',
    'ttl' => 60, // Cache for 1 hour
],

use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;

public function content(Schema $schema): Schema
{
    return $schema
        ->components([
            TextInput::make('site_name')->

namespace App\Filament\Resources\Post\Widgets; // depending on your app structure

use Filament\Schemas\Schema;
use Inerba\DbConfig\AbstractWidgetSettings;

class BlogSettings extends AbstractWidgetSettings
{
    /**
     * Get the name of the setting.
     *
     * @return string The name of the setting.
     */
    protected function settingName(): string
    {
        return 'blog-settings';
    }

    /**
     * Provide default values for the settings.
     *
     * @return array<string, mixed> The default data for the settings.
     */
    public function getDefaultData(): array
    {
        return [];
    }

    /**
     * Define the form schema for the settings page.
     *
     * @param  Schema  $schema  The schema instance.
     * @return Schema The modified schema with components.
     */
    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                // Form components go here
            ])
            ->statePath('data');
    }
}

db_config('website.site_name', 'Default Name');

safe_db_config('website.site_name', 'Default Name');

\Inerba\DbConfig\DbConfig::get('website.site_name', 'Default Name');

\Inerba\DbConfig\DbConfig::set('website.site_name', 'Acme Inc.');

\Inerba\DbConfig\DbConfig::getGroup('website');
// => [ 'site_name' => 'Acme Inc.', 'contact' => ['email' => '[email protected]'] ]

\Inerba\DbConfig\Facades\DbConfig::get('website.site_name');

    use Filament\Forms\Components\TextInput;
    use Filament\Forms\Components\Toggle;
    use Filament\Schemas\Schema;

    /**
     * Set the default values to pre-fill the form.
     *
     * @return array<string,mixed>
     */
    public function getDefaultData(): array
    {
        return [
            'posts_per_page' => 10,
            'allow_comments' => true,
        ];
    }

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('posts_per_page')->

// Store a nested structure
\Inerba\DbConfig\DbConfig::set('profile.preferences', [
    'theme' => 'dark',
    'notifications' => ['email' => true, 'sms' => false],
]);

// Read a nested value with default
db_config('profile.preferences.theme', 'light'); // 'dark'

// Read a missing nested value
db_config('profile.preferences.timezone', 'UTC'); // 'UTC'
bash
    php artisan vendor:publish --tag="db-config-migrations"
    
bash
    php artisan migrate
    
bash
    php artisan make:db-config Website
    
bash
php artisan vendor:publish --tag="db-config-config"
bash
php artisan make:db-config