Installation
composer require francescobruno-cmv/tiny-editor
Publish the config (if needed) with:
php artisan vendor:publish --provider="FrancescoBrunoCmv\TinyEditor\TinyEditorServiceProvider"
Register the Component Add the component to your Livewire blade file:
<livewire:tiny-editor
api-key="{{ config('services.tinymce.key') }}"
wire:model="content"
:settings="['height' => 400]"
/>
First Use Case Bind the editor to a Livewire property:
public $content = '';
// Handle submission
public function save()
{
$this->validate(['content' => 'required']);
// Save to DB
}
config/tiny-editor.php (API key, default settings)app/Http/Livewire/TinyEditor.php (if extending)resources/views/vendor/tiny-editor.blade.php (customization)Livewire Integration
Use wire:model to bind editor content to a Livewire property:
<livewire:tiny-editor wire:model="post.body" />
Customizing TinyMCE
Pass settings via :settings prop (TinyMCE config):
<livewire:tiny-editor
:settings="[
'plugins' => 'image code',
'toolbar' => 'bold italic | code',
'images_upload_handler' => 'uploadImage'
]"
/>
Handling Uploads Implement a Livewire method for file uploads:
public function uploadImage($file, $editorId)
{
$path = $file->store('uploads');
return asset("storage/{$path}");
}
Bind it in Blade:
<livewire:tiny-editor
:upload-handler="['uploadImage']"
/>
Reactive Updates
Listen for editor events (e.g., editorInit, editorChange):
protected $listeners = [
'editorInit' => 'onEditorInit',
'editorChange' => 'onContentChange'
];
.env or a service:
public $apiKey = config('services.tinymce.key');
<livewire:tiny-editor wire:model="post.intro" id="intro-editor" />
<livewire:tiny-editor wire:model="post.content" id="content-editor" />
config/tiny-editor.php:
'presets' => [
'default' => ['height' => 400, 'plugins' => 'image'],
'rich' => ['plugins' => 'image code link', 'toolbar' => 'full'],
],
Use via :preset="rich".API Key Missing
config('services.tinymce.key') is set in .env:
TINYMCE_API_KEY=your_key_here
Invalid API key errors.Livewire Property Not Updating
wire:model or incorrect property name.public $content = ''; // Must match wire:model="content"
Upload Handler Not Triggering
wire:model.public function uploadImage($file, $editorId) { ... }
$editorId to confirm it matches the editor’s ID.CSS/JS Conflicts
<livewire:tiny-editor :styles="['container' => 'my-tinymce-class']" />
Add to your CSS:
.my-tinymce-class { /* override styles */ }
public function mount()
{
$this->log('Editor mounted', 'debug');
}
tinymce.min.js).Custom Plugins
Extend TinyMCE’s functionality by adding plugins to the :settings prop:
<livewire:tiny-editor
:settings="['plugins' => 'your-plugin']"
/>
Register the plugin via TinyMCE’s API in a script:
tinymce.PluginManager.add('your-plugin', function(editor) { ... });
Event Listeners Extend the component to emit custom events:
// In Livewire component
public function onEditorInit()
{
$this->dispatch('editor-ready');
}
Listen in Blade:
@script
window.addEventListener('livewire:init', () => {
Livewire.on('editor-ready', () => { ... });
});
@endscript
Localization
Override TinyMCE’s language files by passing :language:
<livewire:tiny-editor :language="['language' => 'it_IT']" />
Or publish the package’s language files:
php artisan vendor:publish --tag=tiny-editor-lang
Performance
public $lazyLoad = true;
config/tiny-editor.php:
'default' => [
'height' => 300,
'menubar' => false,
],
config() helper:
$apiKey = config('tiny-editor.api_key');
php artisan cache:clear
How can I help you explore Laravel packages today?