iamgerwin/filament-flexible-content 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

iamgerwin/filament-flexible-content

Composer 安装命令:

composer require iamgerwin/filament-flexible-content

包简介

Flexible Content & Repeater Fields for Laravel Filament v4

README 文档

README

Latest Version on Packagist Total Downloads PHP Version Filament Version

Flexible Content & Repeater Fields for Laravel Filament v4. Built with PHP 8.2+ features for maximum performance and type safety.

Features

  • 🎨 Flexible Layout System - Create custom content layouts with ease
  • 🔧 Built for Filament v3 & v4 - Seamlessly integrates with Filament's form builder
  • 🚀 PHP 8.2+ Optimized - Leverages modern PHP features for performance
  • 📦 Preset Support - Bundle layouts into reusable presets
  • 🎯 Type-Safe - Full type declarations and strict typing throughout
  • 🧩 Extensible - Easy to extend with custom layouts and functionality
  • 💾 Cast Support - Eloquent cast for seamless database integration
  • 🛠️ Artisan Commands - Quickly scaffold new layouts
  • 🧪 Fully Tested - Comprehensive test suite using Pest

Requirements

  • PHP ^8.2
  • Laravel ^10.0, ^11.0, or ^12.0
  • Filament ^3.2 or ^4.0

Installation

You can install the package via composer:

composer require iamgerwin/filament-flexible-content

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-flexible-content-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-flexible-content-config"

This is the contents of the published config file:

return [
    'layouts_directory' => app_path('Filament/Flexible/Layouts'),
    'presets_directory' => app_path('Filament/Flexible/Presets'),
    'auto_register_layouts' => true,
    'auto_register_presets' => true,
    'cache' => [
        'enabled' => env('FLEXIBLE_CONTENT_CACHE', true),
        'key' => 'filament-flexible-content',
        'ttl' => 3600,
    ],
    'defaults' => [
        'collapsible' => true,
        'cloneable' => true,
        'reorderable' => true,
        'columns' => 2,
    ],
];

Usage

Basic Usage

Add the flexible content field to your Filament resource:

use IamGerwin\FilamentFlexibleContent\Forms\Components\FlexibleContent;
use App\Filament\Flexible\Layouts\HeroLayout;
use App\Filament\Flexible\Layouts\ContentLayout;

public static function form(Form $form): Form
{
    return $form
        ->schema([
            FlexibleContent::make('content')
                ->layouts([
                    HeroLayout::make(),
                    ContentLayout::make(),
                ])
        ]);
}

Creating Layouts

Create a new layout using the artisan command:

php artisan make:flexible-layout HeroSection

Or create a layout manually:

<?php

namespace App\Filament\Flexible\Layouts;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use IamGerwin\FilamentFlexibleContent\Layouts\Layout;

final class HeroLayout extends Layout
{
    protected ?string $name = 'hero';
    protected ?string $title = 'Hero Section';

    protected function setUp(): void
    {
        parent::setUp();

        $this->icon('heroicon-o-rectangle-group')
            ->fields([
                TextInput::make('heading')
                    ->required()
                    ->maxLength(255),

                Textarea::make('subheading')
                    ->rows(2)
                    ->maxLength(500),
            ]);
    }
}

Using Presets

Create a preset to bundle multiple layouts:

php artisan make:flexible-layout PageBuilder --preset
<?php

namespace App\Filament\Flexible\Presets;

use IamGerwin\FilamentFlexibleContent\Layouts\Preset;
use App\Filament\Flexible\Layouts\HeroLayout;
use App\Filament\Flexible\Layouts\ContentLayout;

final class PageBuilder extends Preset
{
    public function register(): void
    {
        $this->addLayouts([
            HeroLayout::make(),
            ContentLayout::make(),
        ]);
    }
}

Use the preset in your form:

FlexibleContent::make('content')
    ->preset(PageBuilder::class)

Advanced Configuration

FlexibleContent::make('content')
    ->layouts([/* ... */])
    ->minLayouts(1)              // Minimum number of layouts
    ->maxLayouts(10)             // Maximum number of layouts
    ->onlyLayouts(['hero'])      // Limit to specific layouts
    ->collapsible()              // Make blocks collapsible
    ->cloneable()                // Allow cloning blocks
    ->reorderable()              // Allow reordering blocks
    ->columnSpanFull()           // Full width

Conditional Visibility with dependsOn

The FlexibleContent field supports conditional visibility based on other form fields:

// Show flexible content only when type is 'national'
FlexibleContent::make('content')
    ->dependsOn('type', fn ($get) => $get('type') === 'national')
    ->layouts([/* ... */])

// Multiple field dependencies
FlexibleContent::make('content')
    ->dependsOn(['type', 'status'], function ($get) {
        return $get('type') === 'national' && $get('status') === 'published';
    })
    ->layouts([/* ... */])

You can also apply conditional visibility to individual layouts:

class ConditionalLayout extends Layout
{
    protected function setUp(): void
    {
        parent::setUp();

        // Only show this layout when scope is 'global'
        $this->dependsOn('scope', fn ($get) => $get('scope') === 'global');

        $this->fields([
            TextInput::make('title')->required(),
        ]);
    }
}

Database Integration

Add the cast to your model:

use IamGerwin\FilamentFlexibleContent\Casts\FlexibleContentCast;

class Page extends Model
{
    protected $casts = [
        'content' => FlexibleContentCast::class,
    ];
}

Accessing Content in Views

@foreach($page->content as $block)
    @switch($block->layout)
        @case('hero')
            <div class="hero-section">
                <h1>{{ $block->get('heading') }}</h1>
                <p>{{ $block->get('subheading') }}</p>
            </div>
            @break

        @case('content')
            <div class="content-section">
                {!! $block->get('content') !!}
            </div>
            @break
    @endswitch
@endforeach

Working with Content Items

// Check layout type
if ($block->is('hero')) {
    // Handle hero layout
}

// Access data
$heading = $block->get('heading');
$hasHeading = $block->has('heading');

// Access metadata
$order = $block->getMeta('order');

// Convert to array
$array = $block->toArray();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

iamgerwin/filament-flexible-content 适用场景与选型建议

iamgerwin/filament-flexible-content 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 iamgerwin/filament-flexible-content 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-22