klisica/filament-builder-blocks
最新稳定版本:v1.0.0
Composer 安装命令:
composer require klisica/filament-builder-blocks
包简介
Flexible builder blocks generator for Filament
README 文档
README
🏗️ A Simpler Web CMS Builder for Laravel Filament
Create, manage & customize
By re-using Filament's Builder Input this package enables you to create custom section blocks as PHP classes (i.e. DefaultHeader.php) enabling you to use all features supported in Filament.
Each section block uses his own blade view file (i.e. default-header.blade.php) with support for dynamic data binded in PHP classes.
Another great helper functions that are ready-to-use:
renderSections(...)- Returns a fully formatted HTML code for each section,cleanup(...)- Cleans unused attributes and values on store and update methods on filaments Create and Edit pages.
Installation
- Require the package via composer:
composer require klisica/filament-builder-blocks
- Install it to publish the config file:
php artisan filament-builder-blocks:install
-
Open the
config/filament-builder-blocks.phpfile and set thepathvalue to root destination where you'll have you PHP classes (or leave it as it is). -
Run make section command to create your first example section class with the blade view file:
php artisan make:section Hero
Default folder structure example
Main section Hero.php will be displayed in builder dropdown, while child sections ExampleHero.php and AdvancedHero.php will be displayed as toggle buttons.
├── app
│ ├── Sections
│ │ ├── Header
│ │ │ ├── ExampleHero.php
│ │ │ ├── AdvancedHero.php
│ │ │
│ │ ├── Hero.php
Creating layouts for each section block component.
├── resources
│ ├── views
│ │ ├── sections
│ │ │ ├── example-hero.blade.php
│ │ │ ├── advanced-hero.blade.php
Note
To be sure that on running the cleanup() helper your data won't be remove use the content. prefix on make input methods. This is used a handler to avoid storing inputs that you still need to show for descpritive purposes (i.e. Placeholder component). Take the ExampleHero.php as example:
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. ]); } }
Example for adding cleanup on some Filaments Resource Edit Page:
protected function mutateFormDataBeforeSave(array $data): array { return (new FilamentBuilderBlocks)->cleanup($data); }
Rendering components
- Build sections in controller:
$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);
- Display them in a
dynamic.blade.php(or whatever you name it) file:
@foreach($sections as $section) {!! $section !!} @endforeach
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 200
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-29