表单位于foreach循环中时验证

时间:2016-06-21 11:03:51

标签: laravel-5.2

我在验证方面遇到了问题。

我在索引刀片的foreach循环中有图像上传表单。

当我尝试验证时,它显示我不想要的所有地方的错误信息。我只想在我上传图像的部分出错。

@foreach($founders as $founder)
   <tr>
     <td>
       {{ Form::open(['url'=>'/admin/teamMembers/profileImage/'.$founder->id, 'class'=>'form-horizontal','files'=>true]) }}

        {{ Html::image($founder->profilepic,'',['width'=>'100px','id'=>$founder->id, 'class'=>'table-team-img']) }}

        <input onchange="document.getElementById('{{$founder->id}}').src = window.URL.createObjectURL(this.files[0])"
        name="Profilepic" type="file"  placeholder="">
        @if ($errors->has('Profilepic'))
            <span class="help-block">
               {{ $errors->first('Profilepic') }}
            </span>
        @endif
           <br>
       <div>
      <button type="submit" class="btn btn-warning">Update Image</button>
  </div>
{{ Form::close() }}
</td>
@endforeach

我的控制器

public function UpdateImage(Request $request,$id)
{
    $this->validate($request, [
        'Profilepic' => 'required'
    ]);


    $founder = Founder::find($id);

    $destination_path = 'uploads/founder/';

    if ($request->file('Profilepic')) {
        $image = $destination_path . '/' . str_random(6) . '_' . time() . "-" . $request->file('Profilepic')->getClientOriginalName();
        $request->file('Profilepic')->move($destination_path, $image);

        $founder->update([
            'profilepic' => $image
        ]);
        session()->flash('message', 'Image Updated');

        return redirect()->back();
    }

}

提前致谢

0 个答案:

没有答案