1、首先安装laravel ueditor扩展
"stevenyangecho/laravel-u-editor": "~1.4"
在composer.json中增加
然后执行
然后在config/app.php的providers下增加一行
然后执行
2、自定义laravel-admin Form组件
新建组件类app/Admin/Extensions/UEditor:
<?php
namespace App\Admin\Extensions;
use Encore\Admin\Form\Field;
class UEditor extends Field
{
public static $js = [
'laravel-u-editor/ueditor.config.js',
'laravel-u-editor/ueditor.all.min.js',
'laravel-u-editor/lang/zh-cn/zh-cn.js',
];
protected $view = 'admin.ueditor';
public function render()
{
$this->script = <<<EOT
UE.delEditor('$this->id');
var ue_$this->id = UE.getEditor('$this->id');
ue_$this->id.ready(function () {
ue_$this->id.execCommand('serverparam', '_token', '{{ csrf_token() }}');
});
EOT;
return parent::render();
}
}新建视图文件 resources/views/admin/ueditor.blade.php:
<div class="form-group {!! !$errors->has($errorKey) ?: 'has-error' !!}">
<label for="{{$id}}" class="col-sm-2 control-label">{{$label}}</label>
<div class="col-sm-8">
@include('admin::form.error')
<script id="{{$id}}" type="text/plain" name="{{$name}}" style="width: 100%;height: 500px;">{!! htmlspecialchars_decode(old($column, $value)) !!}</script>
@include('admin::form.help-block')
</div>
</div>然后注册进laravel-admin,在app/Admin/bootstrap.php中添加以下代码:
<?php
use App\Admin\Extensions\UEditor;
use Encore\Admin\Form;
Form::extend('editor', UEditor::class);调用:
$form->ueditor('body','内容')->rules('required');效果如:

Comments (0)