1. Go to this page and download the library: Download caiquebispo/quill-editor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// In your Livewire component
public function restoreDraft(): void
{
$this->dispatch('restoreDraft');
}
public function clearDraft(): void
{
$this->dispatch('clearDraft');
}
namespace App\Livewire;
use Livewire\Component;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\On;
class EditorComponent extends Component
{
public string $content = '';
#[On('quillUpdated')]
public function quillUpdated(string $content, string $editorId): void
{
$this->content = $content;
}
public function save(): void
{
// Save your content to database
// Example: Post::create(['content' => $this->content]);
session()->flash('message', 'Content saved successfully!');
}
public function render(): View
{
return view('livewire.editor-component');
}
}
namespace App\Livewire;
use App\Models\Post;
use Livewire\Component;
use Livewire\Attributes\On;
class PostEditor extends Component
{
public Post $post;
public string $content = '';
public function mount(Post $post): void
{
$this->post = $post;
$this->content = $post->content ?? '';
}
#[On('quillUpdated')]
public function quillUpdated(string $content, string $editorId): void
{
$this->content = $content;
}
public function save(): void
{
$this->post->update([
'content' => $this->content
]);
session()->flash('message', 'Post updated successfully!');
}
public function render()
{
return view('livewire.post-editor');
}
}
// In your Livewire component
public function clearEditor(): void
{
$this->dispatch('clearEditor');
}
public function focusEditor(): void
{
$this->dispatch('focusEditor');
}
public function toggleEditor(bool $disabled = true): void
{
$this->dispatch('toggleEditor', disabled: $disabled);
}
public function selectAllEditor(): void
{
$this->dispatch('selectAllEditor');
}
// Access the editor component directly
$editor = $this->getChild('quill-editor');
// Get plain text (without HTML tags)
$plainText = $editor->getPlainText();
// Get word count
$wordCount = $editor->getWordCount();
// Check if editor is empty
$isEmpty = $editor->isEmpty();
// Set content programmatically
$editor->setContent('<p>New content here</p>');
#[On('quillUpdated')]
public function handleContentUpdate(string $content, string $editorId): void
{
// Handle the updated content
$this->content = $content;
}
// In your Livewire component
public function uploadImage($image)
{
$path = $image->store('images', 'public');
$url = Storage::url($path);
// Inject image into editor
$this->dispatch('insertImage', url: $url);
}