aweika / laravel-ueditor by aweika

ueditor for laravel.
97
0
2
Package Data
Maintainer Username: aweika
Maintainer Contact: kller@foxmail.com (aweika)
Package Create Date: 2017-04-13
Package Last Update: 2017-06-27
Language: JavaScript
License: MIT
Last Refreshed: 2024-11-20 03:02:36
Package Statistics
Total Downloads: 97
Monthly Downloads: 1
Daily Downloads: 1
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

laravel-ueditor

ueditor for laravel 5.4

============================

##使用方法:

  1. composer安装

    composer require aweika/laravel-ueditor
    
  2. config/app.php中的providers的数组中添加

    Aweika\LaravelUeditor\LaravelUeditorServiceProvider::class,
    

    config/app.php中的aliases的数组中添加

    'LaravelUeditor' => Aweika\LaravelUeditor\LaravelUeditor::class,
    
  3. 执行下面命令

    php artisan vendor:publish --provider="Aweika\LaravelUeditor\LaravelUeditorServiceProvider" --tag=first
    

    会生成配置文件config/aweika-laravel-ueditor.php 修改其中的package_path这个参数,配置ueditor的资源文件生成的目录。 此参数相对于public目录,比如默认值为aweika-laravel-ueditor,则会将编辑器的资源文件生成到public/aweika-laravel-ueditor目录中。

  4. 执行下面命令

    php artisan vendor:publish --provider="Aweika\LaravelUeditor\LaravelUeditorServiceProvider" --tag=second
    

    会按照上一步设置的路径生成资源文件和一个组件view。

  5. 打开routes/web.php在适当的位置添加如下代码来设置编辑器上传相关操作所需要的路由。

    \LaravelUeditor::routes();
    
  6. 在需要使用编辑器的view文件中调用组件,比如表单控件的名称为element

    • 简单的调用
      @component(\LaravelUeditor::component(), ['field'=>'element'])
      @endcomponent
      
    • 带默认值的调用
      @component(\LaravelUeditor::component(), ['field'=>'element', 'content'=>'default content'])
      @endcomponent
      
    • 带自定义脚本的调用
      @php
          $csrf_token = csrf_token();
          $custom_script = <<<EOD
          <script type="text/javascript">
              var ue = UE.getEditor('content', {
                  initialFrameHeight:300,
                  autoHeightEnabled: false,
                  autoFloatEnabled: false,
                  wordCount:false,
                  elementPathEnabled:false,
                  toolbars: [
                          ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'backcolor', 'simpleupload', 'fullscreen']
                      ]
              });
      
              ue.ready(function() {
                  ue.execCommand('serverparam', '_token', '$csrf_token');
              });
          </script>
      EOD;
      @endphp
      
      @component(\LaravelUeditor::component(), ['field'=>'element', 'content'=>'default content', 'custom_script'=>$custom_script])
      @endcomponent