Block constructor for Filament.
| Package Version | Filament Version |
|---|---|
| 1.x | 3.x |
| 2.x | 4.x |
| 3.x | 5.x |
You can install the package via composer:
composer require cube-agency/filament-constructorYou can publish the config file with:
php artisan vendor:publish --tag="filament-constructor-config"Create your constructor block by using console command:
php artisan filament-constructor:create-block DoubleTextthis will create a new class in Filament\Constructor\Blocks
namespace App\Filament\Constructor\Blocks;
use CubeAgency\FilamentConstructor\Constructor\Blocks\BlockRenderer;
use Filament\Forms\Components\Textarea;
class DoubleTextBlock extends BlockRenderer
{
public function name(): string
{
return 'double_text';
}
public function title(): string
{
return __('DoubleText');
}
public function schema(): array
{
return [
Textarea::make('first_text'),
Textarea::make('second_text'),
];
}
}Add it to config
return [
'blocks' => [
'double_text' => \App\Filament\Constructor\Blocks\DoubleTextBlock::class,
],
];Then add this field to your form
use CubeAgency\FilamentConstructor\Filament\Forms\Components\Constructor;
use Filament\Schemas\Schema;
public static function form(Schema $schema): Schema
{
return $schema
->components([
// ...
Constructor::make('blocks'),
// ...
]);
}Or you can create multiple block groups and use different blocks in each resource
return [
'blocks' => [
'double_text' => \App\Filament\Constructor\Blocks\DoubleTextBlock::class,
],
'image_blocks' => [
'double_image' => \App\Filament\Constructor\Blocks\DoubleImageBlock::class,
],
];use CubeAgency\FilamentConstructor\Filament\Forms\Components\Constructor;
use Filament\Schemas\Schema;
public static function form(Schema $schema): Schema
{
return $schema
->components([
// ...
Constructor::make('blocks')->use(config('filament-constructor.image_blocks')),
// ...
]);
}Constructor blocks has some of the options from Builder\Blocks.
- To add label
public function title(): string
{
return __('Text block');
}- To add icon
public function icon(): string
{
return 'heroicon-o-chat-bubble-left-right';
}- To add maxItems
public function maxItems(): int
{
return 1;
}- To add columns
public function columns(): int
{
return 6;
}To add Builder options to the constructor, add them when defining the constructor field in your page template. For example:
Constructor::make('blocks')
->collapsible()
->collapsed()composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.