如何在 laravel 5 中使用 ckeditor

How to use ckeditor in laravel 5

我正在使用 laravel 创建一个新的博客 Web 应用程序。在这个应用程序中需要一个编辑器来创建博客文章,所以我为此使用 ckeditor

我已经使用官方 ckeditor 文档来安装和设置 ckeditor,但它没有在我的文本区域中显示编辑器。

这是我用的脚本

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
    CKEDITOR.replace('article-ckeditor');
</script>

这是在实现 ckeditor

<div class="form-group">
    {{Form::label('body', 'Body')}}
    {{Form::textarea('body', $post->body, ['id' => 'article-ckeditor', 'class' => 'form-control', 'placeholder' => 'Body Text'])}}
</div>

这里我在控制台日志中发现了一些错误

Failed to load resource: the server responded with a status of 404 (Not Found)    (ckeditor.js:1)

Uncaught ReferenceError: CKEDITOR is not defined at create:108

在 运行 php artisan vendor:publish --tag=ckeditor 命令之后我得到了更多新错误。

Uncaught TypeError: Cannot read property 'unselectable' of null           (ckeditor.js:326 )
    at b (ckeditor.js:326)
    at a.<anonymous> (ckeditor.js:322)
    at a.h (ckeditor.js:11)
    at a.<anonymous> (ckeditor.js:13)
    at a.window.CKEDITOR.window.CKEDITOR.dom.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:14)
    at a.fireOnce (ckeditor.js:13)
    at a.window.CKEDITOR.window.CKEDITOR.dom.CKEDITOR.editor.CKEDITOR.editor.fireOnce (ckeditor.js:14)
    at Object.<anonymous> (ckeditor.js:252)
    at g (ckeditor.js:233)
    at Object.load (ckeditor.js:233)

我正在创建一个博客应用程序,所以我需要一个编辑器,但它不工作,我无法解决这个问题,因为它没有显示任何错误。除了这个编辑器之外,整个应用程序都在工作 属性。

从错误来看,ckeditor.js 文件似乎没有加载。

UniSharp/laravel-ckeditor的官方文档说你应该通过这个命令发布资源:

php artisan vendor:publish --tag=ckeditor

执行该命令后,您应该拥有此文件:your_project_path/public/vendor/unisharp/laravel-ckeditor/ckeditor.js.

更新:最后一个错误(Cannot read property 'unselectable' of null)似乎是ckeditor的已知issue,默认laravel app.js,他们建议从模板 app.blade.php:

的行加载 app.js 中删除 defer
<script src="{{ asset('js/app.js') }}"></script>