Home > Article > Backend Development > Solution to the problem of image list display in laravel-admin integrated ueditor editor
This article mainly introduces the solution to the picture list display problem of laravel-admin integrated ueditor editor. It has a certain reference value. Now I share it with you. Friends in need can refer to it
laravel -Admin integrates ueditor and it is recommended to use laravel-u-editor, which is the laravel composer version of ueditor. Developed based on UEditor 1.4.3.3, supports en, zh_CN, zh_TW, and supports local and Qiniu cloud storage. The default is local upload public/uploads
composer require stevenyangecho/laravel-u-editor 然后在config/app.php的providers下增加一行 Stevenyangecho\UEditor\UEditorServiceProvider::class 执行 php artisan vendor:publish
1.增加组件文件:app/Admin/Extensions/Form/uEditor.php: <?php namespace App\Admin\Extensions\Form; use Encore\Admin\Form\Field; /** * 百度编辑器 * Class uEditor * @package App\Admin\Extensions\Form */ class uEditor extends Field { // 定义视图 protected $view = 'admin.uEditor'; // css资源 protected static $css = []; // js资源 protected static $js = [ 'laravel-u-editor/ueditor.config.js', 'laravel-u-editor/ueditor.all.min.js', 'laravel-u-editor/lang/zh-cn/zh-cn.js' ]; public function render() { $cs=csrf_token(); $this->script = <<<EOT //解决第二次进入加载不出来的问题 UE.delEditor("ueditor"); // 默认id是ueditor var ue = UE.getEditor('ueditor'); ue.ready(function () { ue.execCommand('serverparam', '_token', '$cs'); }); EOT; return parent::render(); } } 2. 增加视图文件: resources/views/admin/uEditor.blade.php <p class="form-group {!! !$errors->has($errorKey) ?: 'has-error' !!}"> <label for="{{$id}}" class="col-sm-2 control-label">{{$label}}</label> <p class="col-sm-8"> @include('admin::form.error') {{-- 这个style可以限制他的高度,不会随着内容变长 --}} <textarea type='text/plain' style="height:400px;" id='ueditor' id="{{$id}}" name="{{$name}}" placeholder="{{ $placeholder }}" {!! $attributes !!} class='ueditor'> {!! old($column, $value) !!} </textarea> @include('admin::form.help-block') </p> </p> 3. 然后注册进laravel-admin,在app/Admin/bootstrap.php中添加以下代码: use App\Admin\Extensions\Form\uEditor; Encore\Admin\Form::extend('ueditor', uEditor::class); 4. 调用: $form->ueditor('content', '内容')->rules('required');
打开文件config\UEditorUpload.php配置七牛配置参数 // 将下一行注释 // 'mode'=>'local',//上传方式,local 为本地 qiniu 为七牛 'mode'=>'qiniu',//上传方式,local 为本地 qiniu 为七牛 //七牛配置,若mode='qiniu',以下为必填. 'qiniu'=>[ 'accessKey'=>'。。。', 'secretKey'=>'。。。', 'bucket'=>'。。。', 'url'=>'。。。',//七牛分配的CDN域名,注意带上http:// ] ],
vendor\stevenyangecho\laravel-u-editor\src\ListsQiniu.php public function getList() { $size = $this->request->get('size', $this->listSize); $start = $this->request->get('start', ''); $auth = new Auth(config('UEditorUpload.core.qiniu.accessKey'), config('UEditorUpload.core.qiniu.secretKey')); $bucketManager = new BucketManager($auth); // 注释掉下面的行 // list($items, $marker, $error) = $bucketManager->listFiles(config('UEditorUpload.core.qiniu.bucket'), $this->path, $start, $size); // 下面三行是修改的 $result1 = $bucketManager->listFiles(config('UEditorUpload.core.qiniu.bucket'), $this->path, $start, $size); $size = count($result1); // 如果不取到items,报找不到key的错误 $items = $result1[0]['items']; // 判断是否错误 if ($size > 2) { return [ "state" => $error->message(), "list" => array(), "start" => $start, "total" => 0 ]; } if(empty($items)){ return [ "state" => "no match file", "list" => array(), "start" => $start, "total" => 0 ]; } $files=[]; // dd($items['items']); foreach ($items as $v) { if (preg_match("/\.(" . $this->allowFiles . ")$/i", $v['key'])) { $files[] = array( 'url' =>rtrim(config('UEditorUpload.core.qiniu.url'),'/').'/'.$v['key'], 'mtime' => $v['mimeType'], ); } } if(empty($files)){ return [ "state" => "no match file", "list" => array(), "start" => $start, "total" => 0 ]; } /* 返回数据 */ $result = [ "state" => "SUCCESS", "list" => $files, "start" => $start, "total" => count($files) ]; return $result; }
The above is the entire content of this article, I hope it will be helpful to everyone's learning, more related Please pay attention to the PHP Chinese website for content!
Related recommendations:
gitbash PHP execution output Chinese random coding solution
The above is the detailed content of Solution to the problem of image list display in laravel-admin integrated ueditor editor. For more information, please follow other related articles on the PHP Chinese website!