<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sitesource / laravel-polymorphic-settings-filament example snippets
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;
use SiteSource\PolymorphicSettings\Filament\Pages\PolymorphicSettingsPage;
class CommerceSettings extends PolymorphicSettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-shopping-cart';
protected static string $view = 'filament.pages.commerce-settings';
public function form(Schema $schema): Schema
{
return $schema->components([
Toggle::make('commerce.stripe.enabled'),
TextInput::make('commerce.stripe.public_key'),
TextInput::make('commerce.stripe.secret_key')->password(), // auto-encrypts
])->statePath('data');
}
}
class GeneralSettings extends PolymorphicSettingsPage
{
public function form(Schema $schema): Schema
{
return $schema->components([
TextInput::make('site_title'),
TextInput::make('contact_email'),
])->statePath('data');
}
}
class TeamSettings extends PolymorphicSettingsPage
{
public function form(Schema $schema): Schema
{
return $schema->components([
TextInput::make('theme.primary_color'),
TextInput::make('theme.logo_url'),
])->statePath('data');
}
protected function scopeFor(): ?Model
{
return auth()->user()->currentTeam;
}
}
TextInput::make('stripe.secret_key')->password()
protected function onSaved(): void
{
parent::onSaved();
Cache::tags('navigation')->flush();
}
use SiteSource\PolymorphicSettings\Filament\Concerns\BindsToSettings;
class MyPage extends Page
{
use BindsToSettings;
public ?array $data = [];
public function mount(): void
{
$this->form->fill($this->fillFromSettings([
'commerce.stripe.enabled',
'commerce.stripe.public_key',
'commerce.stripe.secret_key',
]));
}
public function save(): void
{
$this->persistToSettings(
$this->form->getState(),
encryptedKeys: ['commerce.stripe.secret_key'],
);
}
protected function settingsScope(): ?Model
{
return null;
}
}
bash
php artisan polymorphic-settings:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.