在laravel项目中,使用composer直接引入ueditor百度富文本编辑器。
UEditor integration for Laravel 5.
Github地址:https://github.com/overtrue/laravel-ueditor
安装命令:
composer require "overtrue/laravel-ueditor:~1.0"
配置:
添加下面一行到 config/app.php 中 providers 部分:
Overtrue\LaravelUEditor\UEditorServiceProvider::class,
发布配置文件与资源
php artisan vendor:publish --provider='Overtrue\LaravelUEditor\UEditorServiceProvider'
模板引入编辑器
这行的作用是引入编辑器需要的 css,js 等文件,所以你不需要再手动去引入它们。
@include('vendor.ueditor.assets')编辑器的初始化
<!-- 实例化编辑器 -->
<script type="text/javascript">    
    var ue = UE.getEditor('container');    
    ue.ready(function() {        
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.    });
</script>
<!-- 编辑器容器 -->
<script 
    id="container" 
    name="content" 
    type="text/plain"
>{!! html_entity_decode($post->content ?? old('content')) !!}</script>说明:
5.4+ 请不要忘记
php artisan storage:link
如果你使用的是 laravel 5.3 以下版本,请先创建软链接:
ln -s `pwd`/storage/app/public `pwd`/public/storage
在 config/ueditor.php 配置 disk 为 'public' 情况下,上传路径在:public/uploads/ 下,确认该目录存在并可写。
如果要修改上传路径,请在 config/ueditor.php 里各种类型的上传路径,但是都在 public 下。
请在 .env 中正确配置 APP_URL 为你的当前域名,否则可能上传成功了,但是无法正确显示。
        宠物免费领养小程序,欢迎来踩