Laravel‑KindEditor: Installation, Configuration, and Usage Guide

This article provides a step‑by‑step tutorial for installing the Laravel‑KindEditor package, configuring storage drivers, adding the service provider, publishing assets, setting up the editor in Blade templates, and handling image upload responses with example code snippets for developers.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Laravel‑KindEditor: Installation, Configuration, and Usage Guide

The Laravel‑KindEditor package wraps the KindEditor HTML editor for use in Laravel projects, supporting local, Qiniu, and Alibaba Cloud OSS storage.

Update Log 2018‑06‑15 Release v1.0.0 – completed the KindEditor core and integrated local, Qiniu, and OSS storage.

Installation Methods

1. Add the package to composer.json:

require:{
    "chenhua/laravel5-kindeditor": "~1.0"
}

Then run composer update.

2. Or install directly via Composer: composer require chenhua/laravel5-kindeditor 3. Register the service provider in config/app.php:

Chenhua\Kindeditor\KindeditorServiceProvider::class,

4. Publish the configuration file: php artisan vendor:publish --tag=kindeditor 5. Edit config/kindeditor.php to set the default driver and connection details (local, Qiniu, or Aliyun):

<?php
return [
    "default" => "local",
    "driver" => [
        "local" => [
            "prefix" => "uploads/kindeditor",
        ],
        "qiniu" => [
            "access_key" => "",
            "secret_key" => "",
            "bucket" => "",
            "prefix" => "",
            "domain" => "",
        ],
        "aliyun" => [
            "ak_id" => "",
            "ak_secret" => "",
            "bucket" => "",
            "end_point" => "",
            "prefix" => "",
        ],
    ],
];

Usage in Blade Templates

Add a textarea where the editor will be rendered:

<textarea id="editor_id" name="content" style="width:700px;height:300px;">HTML内容</textarea>
@{{ include('kindeditor::editor', ['editor' => 'editor_id']) }}

Include the required scripts:

<script src="/vendor/kindeditor/kindeditor-all-min.js"></script>
<script src="/vendor/kindeditor/lang/zh-CN.js"></script>

Initialize the editor with custom options:

KindEditor.ready(function(K) {
    window.editor = K.create('#' + '{{$editor}}', {
        uploadJson: "/org/upload_images",
        allowFileManager: false,
        formatUploadUrl: false,
        filePostName: 'file',
        allowImageUpload: true,
        extraFileUploadParams: { _token: '{{ csrf_token() }}' },
        items: [
            'undo','redo','justifyleft','justifycenter','justifyright','justifyfull',
            'insertorderedlist','insertunorderedlist','|','fontname','fontsize','|',
            'forecolor','bold','italic','underline','strikethrough','|','image',
            'pagebreak','link','unlink'
        ],
        afterBlur: function(){ this.sync(); }
    });
});

Backend JSON Response for Image Upload

$data = [
    'error' => 0, // success code
    'url'   => $imgUrl // OSS returned path
];
return json_encode($data);

Following these steps creates an HTML editor with id="editor_id" that supports real‑time preview and uploads images to the configured storage backend.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPinstallationHTML editorKindEditor
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.