aweika/laravel-ueditor

ueditor for laravel.

Installs: 97

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

1.0.1 2017-06-27 03:12 UTC

This package is not auto-updated.

Last update: 2024-11-24 02:52:46 UTC


README

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