This package provides a custom field for Laravel Nova that integrates the SunEditor, a lightweight and flexible WYSIWYG editor.
- Rich text editing capabilities with SunEditor.
- Seamless integration with Laravel Nova.
- Easy configuration and customization.
- Emoji support within editor.
To install the custom field, follow these steps:
-
Install the package via Composer:
composer require webard/nova-suneditor
-
Publish the assets:
php artisan vendor:publish --provider="Webard\NovaSunEditor\FieldServiceProvider"
To use the SunEditor field in your Laravel Nova resource, follow these steps:
-
Import the field in your Nova resource file:
use Webard\NovaSunEditor\SunEditor;
-
Add the field to the
fields
method of your Nova resource:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
SunEditor::make('Content', 'content')
->rules('required', 'string')
->hideFromIndex(),
];
}
SunEditor supports uploading by drag&drop or pasting image directly into editor field. To enable upload, provide withFiles()
method, like in Trix
field:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
SunEditor::make('Content', 'content')
->withFiles('disk','path/to/attachments')
];
}
Unfortunately, upload does not work out of the box with fields in Nova Actions (Trix has same problem). If you need to upload files in Action modal, provide path to upload in settings and handle upload by yourself:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
SunEditor::make('Content', 'content')
->withFiles('disk','path/to/attachments')
->settings([
'imageUploadUrl' => '/your/path/to/handle/upload',
]),
];
}
The SunEditor field can be customized by some methods:
- In
nova-suneditor.php
you can define more buttonLists and name them. Then, you can use buttonList usingbuttonListName
method.
SunEditor::make('Content', 'content')
->buttonListName('my-buttons')
- You can define buttonList directly in field definition:
SunEditor::make('Content', 'content')
->buttonList([
[
'undo',
'redo',
'bold'
]
]);
- You can change settings directly in field definition:
SunEditor::make('Content', 'content')
->settings([
'minHeight' => '500px'
]);
I'm are actively seeking contributions to enhance this package. Here are some features I would love to see implemented:
- multi-language
- image browser
- purging stale attachments like in
Trix
field
We welcome contributions to improve this plugin! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Push your changes to your forked repository.
- Open a pull request to the main repository.
This project is licensed under the MIT License. See the LICENSE.md file for more details.
For questions or support, please open an issue on GitHub.