laravel-admin 富文本编辑

富文本编辑组件在v1.7.0版本之后移除,请选择使用下面的富文本编辑器扩展:

扩展URL
wangEditorhttps://github.com/laravel-admin-extensions/wangEditor
wangEditor2https://github.com/laravel-admin-extensions/wangEditor2
UEditorhttps://github.com/laravel-admin-extensions/UEditor
Summernotehttps://github.com/laravel-admin-extensions/summernote
Quillhttps://github.com/laravel-admin-extensions/quill
CKEditorhttps://github.com/laravel-admin-extensions/ckeditor
Simditorhttps://github.com/laravel-admin-extensions/simditor

这些编辑器默认全部是使用base64和文本一起储存图片的 ,和以往使用的图片独立上传插入图片链接的方式有所不同,这里需要设置下数据库的字段为LongText或者MediumText。

把mysql的 max_allowed_packet设置大一些,比如20M, 把php post的数据限制 post_max_size  设置大一些,以免无法上传大文件。


wangEditor集成进laravel-admin的表单中

laravel-adminextension
1.x1.x
2.x2.x

安装

// laravel-admin 1.x
composer require "laravel-admin-ext/wang-editor:1.*"

// laravel-admin 2.x
composer require laravel-admin-ext/wang-editor

然后

php artisan vendor:publish --tag=laravel-admin-wangEditor

config/admin.php文件的extensions,加上属于这个扩展的一些配置:

    'extensions' => [

        'wang-editor' => [
        
            // 如果要关掉这个扩展,设置为false
            'enable' => true,
            
            // 编辑器的配置
            'config' => [
                
            ]
        ]
    ]

编辑器的配置可以到wangEditor文档找到,比如配置上传图片的地址上传图片

    'config' => [
        // `/upload`接口用来上传文件,上传逻辑要自己实现,可参考下面的`上传图片`
        'uploadImgServer' => '/upload'
    ]

使用

在form表单中使用它:

$form->editor('content');

上传图片

图片上传默认使用base64格式化后与文本内容一起存入数据库,如果要上传图片到本地接口,那么下面是这个接口对应的action代码示例:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

public function upload(Request $request)
{
    $urls = [];

    foreach ($request->file() as $file) {
        $urls[] = Storage::url($file->store('images'));
    }

    return [
        "errno" => 0,
        "data"  => $urls,
    ];
}

CKEditor集成进laravel-admin的表单中

截图:

安装

composer require laravel-admin-ext/ckeditor

然后

php artisan vendor:publish --tag=laravel-admin-ckeditor

config/admin.php文件的extensions,加上属于这个扩展的一些配置:


    'extensions' => [

        'ckeditor' => [
        
            //如果要关掉这个扩展,设置为false
            'enable' => true,
            
            //编辑器配置
            'config' => [
                
            ]
        ]
    ]

 编辑器的配置可以到CKEditor 文档找到,比如配置语言和高度:

    'config' => [
        'lang'   => 'zh-CN',
        'height' => 500,
    ]

使用

在form表单中使用它:

$form->ckeditor('content');

// Set config
$form->ckeditor('content')->options(['lang' => 'fr', 'height' => 500]);

Captcha Code

0 笔记

分享笔记

Inline Feedbacks
View all notes