amidesfahani/filament-tinyeditor
composer require amidesfahani/filament-tinyeditor:^5.0 # For Filament 5.x
php artisan vendor:publish --provider="AmidEsfahani\FilamentTinyEditor\TinyeditorServiceProvider" --tag="config"
php artisan vendor:publish --provider="AmidEsfahani\FilamentTinyEditor\TinyeditorServiceProvider" --tag="public"
Create or Edit resource):
use AmidEsfahani\FilamentTinyEditor\TinyEditor;
TinyEditor::make('content')
->profile('default') // or 'simple', 'full', 'minimal', 'none'
->required();
Replace a standard Textarea or RichEditor field in a Filament form with a TinyMCE-powered editor for richer content editing (e.g., for blog posts, CMS pages, or rich-text fields). Example:
public static function form(Form $form): Form
{
return $form
->schema([
TinyEditor::make('body')
->profile('full')
->columnSpan('full'),
]);
}
Basic Editor Setup
Use predefined profiles (default, simple, full, minimal) for quick integration:
TinyEditor::make('description')
->profile('simple')
->columnSpan('full');
Customizing Toolbars
Override the default toolbar or plugins via the profile() method or by publishing the config:
TinyEditor::make('content')
->profile('custom')
->extraPlugins('export') // Add TinyMCE plugins
->toolbar('bold italic | bullist numlist | link');
File Attachments Configure image/media uploads directly in the field:
TinyEditor::make('article_content')
->fileAttachmentsDisk('s3')
->fileAttachmentsDirectory('articles')
->fileAttachmentsVisibility('private');
RTL Support Enable right-to-left language support:
TinyEditor::make('arabic_content')
->direction('rtl')
->profile('default');
Dynamic Profiles Use conditional logic to switch profiles based on context (e.g., user role):
TinyEditor::make('content')
->profile(auth()->user()->is_admin ? 'full' : 'simple');
Integration with Filament Tables
Display TinyMCE content in tables using Table::column() with a custom view:
Table::column('content')->view('filament-tinyeditor::partials.preview', [
'content' => $record->content,
]);
Custom TinyMCE Config Extend TinyMCE’s default settings via the config file or dynamically:
TinyEditor::make('advanced_content')
->customConfig([
'content_style' => 'body { font-family: Arial; }',
'menubar' => 'edit view insert format tools',
]);
Modal Integration Ensure the editor works seamlessly in Filament modals by setting:
TinyEditor::make('modal_content')
->resize('both') // Adjusts modal height dynamically
->columnSpan('full');
Livewire Component Reuse Reuse the editor in custom Livewire components by extending the field:
use AmidEsfahani\FilamentTinyEditor\TinyEditor;
class CustomEditor extends TinyEditor
{
protected string $view = 'custom.tiny-editor';
}
Multi-Language Support
Combine with Laravel’s localization and TinyMCE’s language config:
TinyEditor::make('translated_content')
->customConfig(['language' => app()->getLocale()]);
Asset Loading Issues
php artisan vendor:publish --provider="AmidEsfahani\FilamentTinyEditor\TinyeditorServiceProvider" --tag="public"
File Upload Permissions
fileAttachmentsDisk) and directory (fileAttachmentsDirectory) are writable. Example:
TinyEditor::make('content')
->fileAttachmentsDisk('public')
->fileAttachmentsDirectory('uploads')
->fileAttachmentsVisibility('public');
Profile Mismatch
default, simple, full, minimal, none). For custom profiles, ensure they’re defined in config/filament-tinyeditor.php.Modal Conflicts
resize('both') and ensure no conflicting JS events (e.g., filament:modal-close).Content Loss on Save
fillable or casts:
protected $casts = [
'content' => 'string', // or 'array' if storing HTML
];
window.tinymceEditors.TinyEditor::make('content')
->customConfig(['debug' => true]);
Filament::debug(true);
Custom Profiles
Add new profiles in config/filament-tinyeditor.php:
'profiles' => [
'custom' => [
'plugins' => 'link image table',
'toolbar' => 'bold italic | link image | table',
],
];
Override Views Publish and modify the editor’s Blade view:
php artisan vendor:publish --provider="AmidEsfahani\FilamentTinyEditor\TinyeditorServiceProvider" --tag="views"
Then extend resources/views/vendor/filament-tinyeditor/tiny-editor.blade.php.
Event Listeners
Listen for TinyMCE events (e.g., init, change) via custom JS:
TinyEditor::make('content')
->extraJs('
document.addEventListener("tinymce.init", (e) => {
console.log("Editor initialized:", e.target.id);
});
');
License Key Add a TinyMCE license key (if required) via config:
'license_key' => env('TINYMCE_LICENSE_KEY'),
simple or minimal profile for non-rich content to reduce load time.media for text-only editors).How can I help you explore Laravel packages today?