Installation:
composer require weave-php/blocknote-filament
Ensure your composer.json meets the requirements (PHP 8.3+, Laravel 11+, Filament 3/4/5).
Register the Plugin (recommended):
In your Panel configuration (e.g., app/Providers/Filament/AdminPanelProvider.php):
public function panel(Panel $panel): Panel {
return $panel
->plugins([
BlockNotePlugin::make(),
]);
}
First Usage: Add the field to a Filament form/resource:
use Weave\BlockNote\Filament\Widgets\Forms\BlockNote;
BlockNote::make('content')
->required()
->columnSpanFull(),
Replace a MarkdownEditor or RichEditor field with a BlockNote field for:
Basic Form Integration:
// In a Filament Form
BlockNote::make('editor_content')
->label('Article Content')
->helperText('Supports headings, lists, and embedded media.')
->required(),
Customizing Toolbar: Override default tools (e.g., hide the "code block" button):
BlockNote::make('notes')
->toolbar([
'bold', 'italic', 'heading', 'bulletList', 'numberedList',
// Exclude 'codeBlock'
]),
Validation & Sanitization: Validate the JSON structure (e.g., ensure non-empty blocks):
BlockNote::make('description')
->rules([
'required',
'json', // Basic JSON validation
function (string $attribute, mixed $value, Closure $fail) {
$blocks = json_decode($value, true);
if (empty($blocks['content'])) {
$fail('The '.$attribute.' must contain at least one block.');
}
},
]),
Database Handling:
{"content":[{"type":"paragraph",...}]}).json_decode() to parse in your models:
$blocks = json_decode($model->content, true);
Dynamic Configuration:
Pass options via configure():
BlockNote::make('dynamic_content')
->configure([
'initialContent' => json_encode(['content' => []]), // Preload empty
'theme' => 'dark', // 'light' or 'dark'
]),
create/edit forms for structured content (e.g., CMS pages, support tickets).return response()->json(['content' => json_decode($model->content)]);
JSON Validation:
json_decode($value, true) to avoid malformed data.->rules(['json', function ($value) {
return json_decode($value, true) !== null;
}]),
Toolbar Customization:
'bold' vs 'boldButton') will break the UI. Use BlockNote’s tool names.// ❌ Won't work
->toolbar(['boldButton']), // Use 'bold' instead
Database Bloat:
gzip before storage.React Dependency:
// vite.config.js
export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.js'],
reactRefresh: true,
}),
],
});
Empty Editor:
initialContent is valid JSON. Use:
->configure(['initialContent' => '{"content":[]}']),
Toolbar Not Loading:
npm run dev
Custom Block Types:
Extend BlockNote’s schema by passing a custom schema in configure():
->configure([
'schema' => [
'blocks' => [
'paragraph',
'heading',
// Add custom block types here
'customBlock' => {
'props': {
'title': 'string',
},
},
],
],
]),
Plugin Hooks: Use Filament’s plugin hooks to modify BlockNote’s behavior globally:
BlockNotePlugin::make()
->modifyFormFieldsUsing(function (array $fields) {
$fields['custom_field'] = BlockNote::make('custom')
->configure(['theme' => 'dark']);
return $fields;
}),
Localization: Override BlockNote’s labels (e.g., toolbar buttons) via Filament’s localization system:
// lang/en/filament-blocknote.php
return [
'toolbar' => [
'bold' => 'Make Bold',
],
];
Performance:
defer: true in the field’s config.columnSpan to control layout:
->columnSpan('full'), // Full-width editor
How can I help you explore Laravel packages today?