Laravel-admin集成UEditor

先下載Ueditor 并解壓到/public目錄,比如放在/public/packages/目錄下
然后新建擴(kuò)展文件app/Admin/Extensions/UEditor.php

  <?php
 namespace App\Admin\Extensions;
 use Encore\Admin\Form\Field;

class UEditor extends Field
{
protected $view = 'admin.u-editor';
protected static $css = [];
protected static $js = [
    '/packages/utf8-php/ueditor.config.js',
    'packages/utf8-php/ueditor.all.js'
];

public function render()
{
    $name = $this->formatName($this->column);

    $this->script = <<<EOT
    //解決第二次進(jìn)入加載不出來(lái)的問(wèn)題
    UE.delEditor("container");
    var ue = UE.getEditor('container',{
    elementPathEnabled: false,
    enableContextMenu: false,
    autoClearEmptyNode: true,
    wordCount: false,
    imagePopup: false,
     autotypeset: {indent: true, imageBlockLine: 'center'}
    });
    ue.ready(function() {
      ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');

    });

EOT;
      return parent::render();
  }
}

新建view resources/views/admin/u-editor.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')
    <textarea type='text/plain' style="height:400px;" id='container' id="{{$id}}" name="{{$name}}" placeholder="{{ $placeholder }}" {!! $attributes !!}  class='ueditor'>
        {!! old($column, $value) !!}
    </textarea>
    @include('admin::form.help-block')
  </div>
</div>

然后在app/Admin/bootstrap.php中引入擴(kuò)展:

use App\Admin\Extensions\UEditor;
use Encore\Admin\Form;
Form::extend('ueditor', UEditor::class);

然后就能在form中使用了:

    $form->ueditor('content');
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容