klisica/filament-builder-blocks

为 Filament 提供灵活的构建块生成器

v1.0.0 2024-05-31 12:48 UTC

This package is auto-updated.

Last update: 2024-09-08 20:16:58 UTC


README

🏗️ 为 Laravel Filament 提供一个更简单的 Web CMS 建造者

Latest Version on Packagist GitHub Code Style Action Status Total Downloads GitHub License

创建、管理 & 自定义

通过重用 Filament 的 Builder Input,此包允许您创建 自定义部分块作为 PHP 类(例如 DefaultHeader.php),从而允许您使用 Filament 支持的所有功能。

每个部分块使用自己的 blade 视图文件(例如 default-header.blade.php),并支持在 PHP 类中绑定动态数据。

其他一些现成的辅助函数

  • renderSections(...) - 返回每个部分的完整格式化 HTML 代码,
  • cleanup(...) - 在 Filament 的创建和编辑页面的存储和更新方法上清除未使用的属性和值。

安装

  1. 通过 composer 需求此包
composer require klisica/filament-builder-blocks
  1. 安装它以发布配置文件
php artisan filament-builder-blocks:install
  1. 打开 config/filament-builder-blocks.php 文件并将 path 值设置为根目标位置,您将在其中拥有您的 PHP 类(或保留原样)。

  2. 运行 make section 命令以创建您的第一个示例部分类及其 blade 视图文件

php artisan make:section Hero

默认文件夹结构示例

主部分 Hero.php 将显示在构建器下拉菜单中,而子部分 ExampleHero.phpAdvancedHero.php 将作为切换按钮显示。

├── app
│   ├── Sections
│   │   ├── Header
│   │   │   ├── ExampleHero.php
│   │   │   ├── AdvancedHero.php
│   │   │
│   │   ├── Hero.php

为每个部分块组件创建布局。

├── resources
│   ├── views
│   │   ├── sections
│   │   │   ├── example-hero.blade.php
│   │   │   ├── advanced-hero.blade.php

注意

为了确保在运行 cleanup() 辅助函数时您的数据不会被删除,请在 make 输入方法中使用 content. 前缀。这用作处理程序,以避免存储您仍需要显示用于描述目的的输入(例如占位符组件)。以 ExampleHero.php 为例

class ExampleHero extends AbstractSectionItemProvider
{
    public function getFieldset(): Fieldset
    {
        return Fieldset::make($this->getName())
            ->schema([
                Placeholder::make('contact_links')->columnSpanFull(),  // Will get cleared out.
                TextInput::make('content.heading'),    // Will keep on save methods.
            ]);
    }
}

在 Filament 资源编辑页面上添加 cleanup 的示例

protected function mutateFormDataBeforeSave(array $data): array
{
    return (new FilamentBuilderBlocks)->cleanup($data);
}

渲染组件

  1. 在控制器中构建部分
$sections = (new FilamentBuilderBlocks)->renderSections(
    sections: $pages->content,    // Page sections stored in content column
    wrappingSections: $layout->content    // Layout sections stored in content column (includes the `yield` field),
    configs: ['page' => $page, 'layout' => $layout]    // Can be whatever you need to bind in `blade.php` files
);

return view('dynamic')->with('sections', $sections);
  1. dynamic.blade.php(或您命名的任何文件)中显示它们
@foreach($sections as $section)
    {!! $section !!}
@endforeach

更改日志

有关最近更改的更多信息,请参阅 CHANGELOG

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件