outerweb / filament-layout-builder
This package extends the filament builder field to work with predefined layout blocks to build the content of a page.
Requires
- php: ^8.0
- filament/filament: ^3.2
- laravel/framework: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.16
README
This package extends the filament builder field to work with predefined layout blocks to build the content of a page.
Installation
You can install the package via composer:
composer require outerweb/filament-layout-builder
Add the plugin to your desired Filament panel:
use OuterWeb\FilamentLayoutBuilder\Filament\FilamentLayoutBuilder; class FilamentPanelProvider extends PanelProvider { public function panel(Panel $panel): Panel { return $panel // ... ->plugins([ FilamentLayoutBuilderPlugin::make(), ]); } }
Usage
Creating layout blocks
Create all your layout blocks in the app/View/Components/LayoutBuilder
directory. Each layout block should extend the Outerweb\FilamentLayoutBuilder\View\Components\Block
class.
namespace App\View\Components\LayoutBuilder; use Outerweb\FilamentLayoutBuilder\View\Components\Block; class Article extends Block { // ... }
Define the view
You can define which view to render by setting the $view
property.
class Article extends Block { protected string $view = 'components.layout-builder.article'; }
Define the fields for the Filament form
You can define the fields for the Filament form by adding a schema
method to the block.
class Article extends Block { // ... public function schema(): array { return [ // ... ]; } }
Formatting data / Fetching data from the database
You can define a formatData
method on your block to format the data before it is passed to the view.
This can be useful to fetch data from the database or to format the data before it is passed to the view.
class Article extends Block { // ... public function formatData(array $data): array { $data['images'] = Image::whereIn('id', $data['images'] ?? [])->get(); return $data; } }
Using the make command
You can use the make:layout-builder-block
command to generate a new layout builder block.
php artisan make:layout-builder-block Article
This will generate a new layout builder block in the app/View/Components/LayoutBuilder
directory: app/View/Components/LayoutBuilder/Article.php
.
And a new view in the resources/views/components/layout-builder
directory: resources/views/components/layout-builder/article.blade.php
.
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.