Php 为什么没有更新Laravel 5.6中编辑视图文件中的图像?

Php 为什么没有更新Laravel 5.6中编辑视图文件中的图像?,php,mysql,laravel-5,Php,Mysql,Laravel 5,我已在我的laravel应用程序中编辑刀片文件。在此编辑表单中,将保存到两个表的数据更新到车辆并上载。我在编辑刀片文件更新图像上传表中有以下代码 @foreach( $vehicles-> uploads as $upload) <img id="preview" src="{{asset((isset($upload) && $upload->resized_name!

我已在我的laravel应用程序中编辑刀片文件。在此编辑表单中,将保存到两个表的数据更新到车辆并上载。我在编辑刀片文件更新图像上传表中有以下代码

@foreach( $vehicles-> uploads as $upload)

                    <img id="preview"
                         src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
                         height="200px" width="200px"/>
                    <input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
                    <br/>
                    <a href="javascript:changeProfile();">Add Image</a> |
                  <a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>
<hr>
                   @endforeach
                    @endif 

但当我附加图像并单击更新按钮时,上传表中并没有更新图像。如何解决此问题?

您的HTML代码错误

  • 不要在
    input
    元素中使用
    style=“display:none”
    。如果它们被隐藏,浏览器将忽略它

  • 不要将CSRF令牌与输入文件合并

  • 试试这个:

    @foreach( $vehicles-> uploads as $upload)
      <img id="preview"  src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}" height="200px" width="200px"/>
      <input class="form-control" name="files[]" type="file" id="files" enctype="multipart/form-data">
      {{ csrf_field() }}
      <br/>
      <a href="javascript:changeProfile();">Add Image</a> |
      <a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a>
      <hr>
    @endforeach
    
    @foreach($vehicles->上传为$upload)
    已调整大小的_名称!=''?'图像/'.$upload->调整大小的_name:'images/noimage.png')}“height=“200px”width=“200px”/
    {{csrf_field()}}
    
    |
    @endforeach
    我认为您在更新控制器中使用了错误的方法

    if (!is_array($photos)) {
        $photos = [$photos];
    }
    
    请尝试此方法将字符串转换为数组

    if (!is_array($photos)) {
        $photos = explode(' ', $photos);
    }
    
    if (!is_array($photos)) {
        $photos = [$photos];
    }
    
    if (!is_array($photos)) {
        $photos = explode(' ', $photos);
    }