nasirkhan/laravel-jodit
Laravel package integrating the Jodit WYSIWYG editor as a reusable Blade component. Works in Blade, view components, and Livewire with wire-model syncing. Includes a server-side file browser/uploader connector, CDN-loaded assets, and configurable toolbar and storage options.
Installation
composer require nasirkhan/laravel-jodit
Publish the config (optional but recommended for customization):
php artisan vendor:publish --tag=jodit-config
Ensure Asset Stacks
Add these to your main layout file (e.g., resources/views/layouts/app.blade.php):
@stack('after-styles')
@stack('after-scripts')
First Use Case Drop the component into a form in Blade:
<x-jodit::editor name="content" :value="old('content', $post->content ?? '')" />
name prop.
<x-jodit::editor name="description" :value="$page->description" />
<form method="POST" action="{{ route('posts.update', $post) }}">
@csrf
@method('PUT')
<x-jodit::editor name="content" :value="old('content', $post->content)" required />
<button type="submit">Save</button>
</form>
wire-model.
<x-jodit::editor name="body" :value="$body" wire-model="body" />
debounce prop (default: 300ms).
<x-jodit::editor name="content" wire-model="content" debounce="500" />
buttons prop (array, JSON string, or PHP-style string).
<x-jodit::editor
name="editor"
:buttons="['bold', 'italic', '|', 'link', 'image']"
/>
profile="full" for a comprehensive toolbar.
<x-jodit::editor name="content" profile="full" />
file-browser="false".
<x-jodit::editor name="excerpt" file-browser="false" />
<x-jodit::editor
name="content"
connector-url="{{ route('admin.jodit.connector') }}"
/>
php artisan vendor:publish --tag=jodit-config
// config/jodit.php
'disk' => 's3',
'base_path' => 'uploads/jodit',
'max_file_size' => 5120, // 5MB
Missing Asset Stacks
@stack('after-styles') and @stack('after-scripts') are in your layout.404 errors on Jodit CDN assets.Livewire Sync Issues
wire-model prop matches a public Livewire property.wire:ignore is auto-applied (check component source).File Upload Permissions
500 errors.config/jodit.php) has write permissions.StorageException.Toolbar Buttons Not Rendering
profile="full" to test if the issue is button-specific.jodit.min.css, jodit.min.js).GET /jodit-connector).Nasirkhan\LaravelJodit entries during uploads or connector calls.php artisan config:clear
Custom File Manager Backend
'file_manager.backend' => 'custom' in config and pointing connector-url to your endpoint.Middleware for Connector
// config/jodit.php
'route' => [
'middleware' => ['web', 'auth', 'role:admin'],
],
Dynamic Config
config(['jodit.disk' => 's3']) in middleware or controllers.Custom Editor Options
config prop (if supported in future updates):
<x-jodit::editor
name="content"
:config="['toolbarButtonSize' => 'small']"
/>
profile="minimal" for lightweight editors (e.g., comments).use Illuminate\Validation\Rules\RequiredIf;
public $content;
protected $rules = [
'content' => ['required', 'string', new RequiredIf($this->isAdmin)],
];
strip_tags or HTML purifier (e.g., beberlei/doctrine-extensions) for stored content.// routes/web.php
Route::any('jodit-connector', fn() => response()->json([]));
// config/jodit.php
'defaults' => [
'showCharsCounter' => false,
'showWordsCounter' => false,
],
```markdown
### **Common Anti-Patterns**
- **Hardcoding Connector URL**: Avoid hardcoding `/jodit-connector` in Blade; use `route()` helper or config.
- **Ignoring `wire:ignore`**: Manually adding `wire:ignore` to the editor’s container can break Livewire sync.
- **Overriding CDN URLs Without Testing**: Always test custom CDN paths in staging before production.
- **Skipping Validation**: Trusting user-uploaded files (e.g., PDFs) without validation can pose security risks.
How can I help you explore Laravel packages today?