Php 拉雷维尔5号酒店;Summernote-上载的图像未显示

Php 拉雷维尔5号酒店;Summernote-上载的图像未显示,php,laravel,summernote,Php,Laravel,Summernote,我正在尝试在基于Laravel 5的网站上安装summernote。然而,无论我做什么,我都不能让上传的图像文件显示在编辑器上 $(document).ready(function() { $.ajaxSetup({ headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') } }); $('#summernote').summernote({ height: 400, onImageUpload

我正在尝试在基于Laravel 5的网站上安装summernote。然而,无论我做什么,我都不能让上传的图像文件显示在编辑器上

$(document).ready(function() {
$.ajaxSetup({
    headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
});
$('#summernote').summernote({
    height: 400,
    onImageUpload: function(files) {
        data = new FormData();
        data.append("image", files[0]);
        $.ajax({
            data: data,
            type: "POST",
            url: "/image/upload",
            cache: false,
            contentType: false,
            processData: false,
            success: function(url) {
                console.log(url);
                // trying to make the image show up here...
            }
        });
    }
});
这是php代码,它可以工作

public function upload_image(ImageRequest $request)
{
    if($request->hasFile('image')){
        $filename = str_random(20).'_'.$request->file('image')->getClientOriginalName();
        $image_path = base_path() . '/public/images/thread/';
        $request->file('image')->move(
            $image_path, $filename
        );
        echo $filename;    
    }
    else{
        echo 'Oh No! Uploading your image has failed.';
    }
}
我使用的是Summernote的最新主版本,以下是我迄今为止尝试过的事项列表:

  • 试过上面说的,但运气不好
  • 访问并尝试了“$summernote.summernote('insertNode',imgNode);”但只会得到错误投诉“TypeError:a.nodeName未定义”
  • 嗯,我的代码是基于but'editor.insertImage(welEditable,url);'已弃用,因此不再有用
  • 尝试了以下基于#2的代码。基本上是想看看是否可以添加来自其他网站的图片——假设我的图片路径是错误的。但不起作用

    //完整路径

    $(“#summernote”).summernote(“插入图像”,“插入图像”)

    //如果没有,是否使用“文件名”选项的完整路径

    $('#summernote').summernote(“插入图像”,“文件名”)

    //如果不是,路径+文件名

    $('#summernote').summernote(“插入图像”,“fish1.jpg”)

    //如果不是,路径+/

    $('#summernote').summernote(“插入图像”,“fish1.jpg”)

  • 如果可以添加数据图像,请尝试,并且有效。但是为什么。

    //数据图像

    $(“#summernote”).summernote(“插入图像”,“数据:image/jpeg;base64,/9j/4AAQSkZ…blahblah…”)

  • 此时,我了解到,$('#summernote').summernote(“insertImage”,…)实际上正在工作,但image url参数可能不工作。是否有人在最新版本的Summernote中成功实现了此功能?或我是不是遗漏了什么?

    找到了答案

    base_path()为我的PC上上载的文件提供了一个物理本地路径。但是,整个过程都在MAMP上运行。因此,url必须类似于“…”


    }))

    您也可以将MAMP上的端口更改为默认端口。下面是一个很好的解决方案,我为您提供了所有您想要的。。。。。。。只需转到此链接
    $(document).ready(function() {
    var IMAGE_PATH = 'http://localhost:8000/images/thread/';
    
    $.ajaxSetup({
        headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content')     }
    });
    $('#summernote').summernote({
        height: 400,
        onImageUpload: function(files) {
            data = new FormData();
            data.append("image", files[0]);
            $.ajax({
                data: data,
                type: "POST",
                url: "/image/upload",
                cache: false,
                contentType: false,
                processData: false,
                success: function(filename) {
                    var file_path = IMAGE_PATH + filename;
                    console.log(file_path);
                    $('#summernote').summernote("insertImage", file_path);
                }
            });
        }
    });