Image 多个图像更新Laravel已删除

Image 多个图像更新Laravel已删除,image,laravel,edit,Image,Laravel,Edit,大家好,如果有人能帮我,我有更新图片的代码,当我上传另一张图片时,它可以正常工作,我不接触其他人,例如,我更改的第一张图片,我上传了一张图片,其他三张我不接触的图片,我单击提交编辑按钮,当我返回编辑视图时,我只能看到我更改的一张照片,其他三张照片都不见了 这是刀片: <form class="form-horizontal" method="POST" action="{{ action('website\questions\MatchLinesWithPhot

大家好,如果有人能帮我,我有更新图片的代码,当我上传另一张图片时,它可以正常工作,我不接触其他人,例如,我更改的第一张图片,我上传了一张图片,其他三张我不接触的图片,我单击提交编辑按钮,当我返回编辑视图时,我只能看到我更改的一张照片,其他三张照片都不见了

这是刀片:

  <form class="form-horizontal" method="POST"
            action="{{ action('website\questions\MatchLinesWithPhotosController@updateQuestion', ['id' => $question->id]) }}"
            enctype="multipart/form-data">
            {{ csrf_field() }}

            @include('website.questions.general-update-header')

            <div class="row">
                <div class="col-lg-5">
                    <label style="padding-left: 10px">
                        <h4 class="box-title">@lang('general.options_for_answers'):</h4>
                        <em class="text-caption" id="caption-question-type"> *@lang('general.chose_correct_multiple_choice_photo')</em>
                    </label>
                </div>
            </div>

            <div class="optionsFormMatchlinePhotos">

                      @for($i=0; $i<=(count($answers->where('deleted', 0))/2)-1; $i++)

              <div class="col-md-6" id="option{{ $i }}">
                <div class="row">
                    <div class="col-md-6 col-md-offset-2">
                        <?php $option = $answers->where('deleted', 0)->where('order', $i)->where('is_key', 1)->first(); ?>

                        <div class="info-box answer-with-photo-option">

                           <img src="{{url('/')}}/images/answers/{{ $option->id }}/medium/{{ $option->image_path }}" class="answer-image-create" id="image{{ $i }}">

                           </div>     @if($option)<input onchange="readURL(this, {{ $i }});" type="file" name="image{{ $i }}" id="<?php echo 'answer_file'.$i;?>" style="
                           margin-top: -19%;
                           padding-bottom: 9%;
                           " />
                           @endif
                       </div>
                   </div>
                   <div class="row">
                    <div class="form-group {{ $errors->has('options.'.$i) ? ' has-error': '' }}">
                        <div class="col-md-12">
                           <div class="col-md-3" style="width: 20%;">


                             {{--    <input  type="text" name="options[{{ $i }}]" value="{{ $i }}" style="display :none" /> --}}
                         </div>
                         <input  type="text" name="matchanswer[{{ $i }}]" value="{{ $i }}" style="display :none" />

                         <?php $match = $answers->where('deleted', 0)->where('order', $i)->where('is_key', 0)->first(); ?>


                         <div class="col-md-5">
                             @if($match)      
                             <input type="text" name="match{{ $i }}" value="{{$match->text}}"
                             class="form-control" placeholder="@lang('general.match') {{ $i + 1}}">
                             @else 
                             <input type="text" name="match{{ $i }}" value=""
                             class="form-control" placeholder="@lang('general.match') {{ $i + 1}}">
                             @endif

                             @if($errors->has('match.'.$i))
                             <div class="col-md-12"></div>
                             <span class="help-block">
                                <strong>{{ $errors->first('match.'.$i) }}</strong>
                            </span>
                            @endif


                        </div>

                        <div class="col-md-4">
                            <button type="button" value="{{ $i }}" class="btn btn-flat btn-default btn-sm" id="delete_option" title="@lang('buttons.remove_option')">
                                <i class="fa fa-trash-o" aria-hidden="true"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        @endfor
    </div>
 public function editQuestionForm($id){
        $question = Question::findOrFail($id);
        $answers  = MatchLineAnswer::where('question_id',  $id)->get();
        return view('website.questions.partials.matchlineswithphotos.edit-matchlineswithphotos',compact('question', 'answers'));
        return session('message');
    }

    public function updateQuestion(MatchLinesWithPhotosFormRequest $request, $id){
            $QuestionController = new QuestionController();
            $QuestionController->UpdateQuestion($request, $id);

            MatchLineAnswer::where('question_id', $id)->update(['deleted' => 1]);
 $to_delete_answers = MatchLineAnswer::select('id')->where('question_id', $id)->get();
        MatchLineAnswer::where('question_id', $id)->update(['deleted' => 1]);

        $imgController = new ImagesController();
        $element = 'answers';

        foreach($to_delete_answers as $deleted_answer){
            $imgController->deleteImage($element, $deleted_answer->id);
        }

        foreach ($request['matchanswer'] as $key => $option){
                 $answer_create =   MatchLineAnswer::create([
                        'question_id' => $id,
                        'order'  => $option,

                        'is_key' => 1
                    ]);

                   $img = $request->file('image'. $option);

            $create_answer_id = $answer_create->id;

            $imgController->uploadAnswerImage($img, $element, $create_answer_id);

            $answer_update = MatchLineAnswer::where('id', $create_answer_id)->update(['image_path'=> $imgController->getUniqueNameAttribute()]);
                    MatchLineAnswer::create([
                        'question_id' => $id,
                        'order'  => $option,
                        'text'   => strip_tags($request['match'.$option]),
                        'is_key' => 0
                    ]);
                }
        $test_id = Question::where('id',  $id)->first();
        session()->flash('message', 'Question successfully updated');
        return redirect()->action('website\tests\CompleteTestController@showAllTestInfo', ['test_id' => $test_id->test_id]);
    }