dongxuan1314 2018-11-27 00:08
浏览 56

输入文件图像阵列更新 - Laravel

I want to update my file input images. As soon as I update one image, the other images are removed. Why is that? I want to keep them with the new uploads. Help me please, thanks.

[Here is an image of the problem][1]

Controller

Update, public function, here is where I put the logic of the code

public function update(Request $request, $id)
{
          $this->validate($request, [
        'inflightmagz_date' => 'required',
        'infightmagazine_pdf.*' => 'image|nullable|max:1999'
    ]);

    $inflightmags = [];

    if ($request->has('infightmagazine_pdf'))
    {   
        //Handle File Upload


        foreach ($request->file('infightmagazine_pdf') as $key => $file)
        {
            // Get FileName
            $filenameWithExt = $file->getClientOriginalName();
            //Get just filename
            $filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
            //Get just extension
            $extension = $file->getClientOriginalExtension();
            //Filename to Store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload Image
            $path = $file->storeAs('public/infightmagazine_pdfs',$fileNameToStore);
            array_push($inflightmags, $fileNameToStore);
        }

        $fileNameToStore = serialize($inflightmags);
    }



    $inflightmagContent =  InflightMagazine::find($id);
    $inflightmagContent->inflightmagz_date = $request->input('inflightmagz_date');
       foreach ($inflightmags as $key => $value) {

        $implodedInflight = implode(' , ', $inflightmags);
        if($request->hasFile('infightmagazine_pdf')){
        $inflightmagContent->infightmagazine_pdf = $implodedInflight;
        }

    }
    $inflightmagContent->save();
    return redirect('/admin/airlineplus/inflightmagazines')->with('success', 'Content Updated');
}

View, edit.blade.php

  {!! Form::open(['action'=>['Admin\FleetsController@update',$fleet->id], 'method' => 'POST','enctype'=>'multipart/form-data', 'name' => 'add_name', 'id' => 'add_name']) !!}

        <div class="table-responsive">
          <table class="table table-bordered" id="dynamic_field">
            <tr>
              <td>   {{Form::text('title', $fleet->title, ['class' => 'form-control', 'placeholder' => 'Enter a Title', 'id'=>"exampleFormControlFile1"])}}<br>

                {{Form::textarea('description', $fleet->description, ['class' => 'form-control', 'placeholder' => 'Enter a Description'])}} <br>
                <div class="card card-body col-md-8">

                @foreach(explode(' , ' ,$fleet->fleet_image) as $content)
                  <img src="{{ asset('storage/fleet_images/' . $content) }}" style="width:50px;height:50px;"><br/>

                  {{ Form::file('fleet_image[]',['id'=>'exampleFormControlFile1']) }}<br/>
                  @endforeach 
                </div>
             </td>

            </tr>
          </table>
          {{Form::hidden('_method', 'PUT')}}
          {{Form::submit('submit', ['class'=>'btn btn-primary', 'name'=>'submit'])}}
        </div>
    {!! Form::close() !!}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类