CKEditor, A famous WYSIWYG editor for web.
- Version
1.2
have published on2022/05/25
, updateCKEditor(4)
to current newest version4.19.0
, adapt to image uploads of new version
This package have been tested for Laravel 5
up versions. It's compatible with Laravel from 5
to 9
by all versions.
Add "douyasi/laravel-ckeditor": "~1.0"
to your Laravel project composer.json
file.
Or, just execute composer require "douyasi/laravel-ckeditor:~1.0"
command in your terminal when change to target project directory.
$ cd /path/to/your/laravel/project
$ vim composer.json
# add "douyasi/laravel-ckeditor": "~1.0" to it
$ composer install/update -vvv
# or execute
$ composer require "douyasi/laravel-ckeditor: ~1.0"
If Laravel package discovery failed, you need to add code below to Laravel config/app.php
file:
'providers' => [
'Douyasi\CKEditor\CKEditorServiceProvider',
],
Execute artisan
command below in terminal to publish all assets by this package.
php artisan vendor:publish --provider="Douyasi\CKEditor\CKEditorServiceProvider" --force
Then, serve your Laravel app, and visit links below.
$ php artisan serve
# then visit
# http://127.0.0.1:8000/laravel-ckeditor/example/basic
# http://127.0.0.1:8000/laravel-ckeditor/example/standard
# http://127.0.0.1:8000/laravel-ckeditor/example/full
/laravel-ckeditor/example/basic
for basic mode, and /laravel-ckeditor/example/standard
for standard mode, and /laravel-ckeditor/example/full
for full mode.
Images will be upload to public/uploads/content
directory, and the config file of this package is located in config/
directory named ckeditor.php
.
See the
example.blade.php
code inresources\views
directory, you need add{!! ckeditor_js() !!}
and{!! ckeditor_css() !!}
in your blade template file for loading CKEditor's static assets.
customized
mode as same as full mode, you can modify it (located in resource/views/vendor/ckeditor/parts/customized.blade.php
directory) after package asset published. Other versions should not be modified.
Here is an example of full
mode of CKEditor in blade html/php file. Include the code @include('ckeditor::parts.basic', ['editorId' => 'editor1'])
when using basic mode. The value of editorId
should be as same as the value of id
in html textarea
element (that rendered as CKEditor
instance here). Other modes are similar without examples here.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CKEditor Example</title>
{!! ckeditor_js() !!}
{!! ckeditor_css() !!}
</head>
<body>
<textarea id="editor1" cols="10" rows="10">
<p>This is some sample text. You are using <a href="http://ckeditor.com">CKEditor</a>, an online <abbr title="What You See Is What You Get">WYSIWYG</abbr>&nbsp;editor.</p>
</textarea>
@section('ckeditorExtraScript')
// add some addon config, ref: https://sdk.ckeditor.com/ or https://docs.ckeditor.com/ckeditor4/docs/
language: 'zh-TW',
uiColor: '#9AB8F3',
filebrowserImageUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&type=Images&by=btn_up',
// filebrowserUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&by=btn_up',
imageUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&type=Images&by=drop_or_clipboard_up', // only for image
// uploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&by=drop_or_clipboard_up',
@overwrite
@include('ckeditor::parts.full', ['editorId' => 'editor1'])
</body>
</html>
Make your own image or file upload code, just change usingLocalPackageUploadServer
value to false
in ckeditor.php
file to disable image upload by this package.
Support upload a image by three ways:
- btn upload: traditional form upload, need to select a file and click a button
- drop upload: drop/drag image file to browser editor area, then upload automatically
- clipboard upload: screen shot to clipboard and paste it to editor area, then upload automatically
Setting filebrowserImageUploadUrl
or filebrowserUploadUrl
value when using traditional form upload, setting imageUploadUrl
or uploadUrl
value when using drop or clipboard upload.
filebrowserImageUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&type=Images&by=btn_up',
imageUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&type=Images&by=drop_or_clipboard_up',
filebrowserUploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&by=btn_up',
uploadUrl : '/laravel-ckeditor/upload?_token={!! csrf_token() !!}&by=drop_or_clipboard_up',
blog: http://douyasi.com
Copyright (c) 2014-2099
douyasi