承接 sitesource/laravel-polymorphic-settings-filament 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sitesource/laravel-polymorphic-settings-filament

Composer 安装命令:

composer require sitesource/laravel-polymorphic-settings-filament

包简介

Filament integration for sitesource/laravel-polymorphic-settings — base page class and trait that auto-bind settings to Filament forms.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A base Filament page class and helper trait that auto-bind your form schema to sitesource/laravel-polymorphic-settings. Stop hand-rolling mount() / save() plumbing on every settings page.

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

That's it. Mount pulls every field's current value from the settings store. Save persists every field back, encrypting any TextInput->password() field at rest. No mount() or save() to write yourself.

Installation

composer require sitesource/laravel-polymorphic-settings-filament

You'll also need the core package installed and migrated:

php artisan polymorphic-settings:install

Filament 4.x or 5.x is required. (Filament 3.x is supported by the v0.1.x line of this package.)

Usage

Global settings page

The default scope is global — settings live alongside PolymorphicSettings::global() reads/writes:

class GeneralSettings extends PolymorphicSettingsPage
{
    public function form(Schema $schema): Schema
    {
        return $schema->components([
            TextInput::make('site_title'),
            TextInput::make('contact_email'),
        ])->statePath('data');
    }
}

Scoped to a model (per-team, per-tenant, per-user)

Override scopeFor() to return the model whose settings you're editing:

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

Encryption

Any TextInput marked with ->password() is automatically persisted as encrypted: true. The Filament form continues to work normally — the user types a plaintext value, the page encrypts on save, and the next mount decrypts transparently.

TextInput::make('stripe.secret_key')->password()

Customising the post-save UX

Default behaviour is a Filament success notification. Override onSaved() to do anything else.

protected function onSaved(): void
{
    parent::onSaved();
    Cache::tags('navigation')->flush();
}

Trait variant: BindsToSettings

If you want to keep your own Page base (or use this on any Livewire component, not just Filament pages), use the trait:

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

The trait gives you fillFromSettings(array $keys): array and persistToSettings(array $values, array $encryptedKeys = []): void. You own the form schema and the lifecycle — the trait just bulk-reads and bulk-writes the store.

Testing

composer test

13 tests, 23 assertions. PHPStan level 5 + Pint clean.

Changelog

See CHANGELOG.md.

Credits

License

MIT — see LICENSE.md.

sitesource/laravel-polymorphic-settings-filament 适用场景与选型建议

sitesource/laravel-polymorphic-settings-filament 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「admin」 「configuration」 「laravel」 「Settings」 「polymorphic」 「laravel-settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sitesource/laravel-polymorphic-settings-filament 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sitesource/laravel-polymorphic-settings-filament 我们能提供哪些服务?
定制开发 / 二次开发

基于 sitesource/laravel-polymorphic-settings-filament 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 92
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25