This package extends the filament builder field to work with predefined layout blocks to build the content of a page.
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(),
]);
}
}
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
{
// ...
}
You can define which view to render by setting the $view
property.
class Article extends Block
{
protected string $view = 'components.layout-builder.article';
}
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 [
// ...
];
}
}
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;
}
}
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
.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.