klisica / filament-builder-blocks
Flexible builder blocks generator for Filament
Fund package maintenance!
klisica
Requires
- php: ^8.2
- filament/filament: ^3.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2025-05-12 19:33:02 UTC
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.php
file and set thepath
value 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.