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');
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');
}
}
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'