Laravel 5 Laravel 5.8图像多上传验证

Laravel 5 Laravel 5.8图像多上传验证,laravel-5,Laravel 5,大家好,我的UploadController中有这样的东西: $this->validate($request, [ 'covers' => 'required|mimes:jpg,jpeg,png,bmp|max:20000' ],[ 'covers.required' => 'Please upload an image', 'covers.mimes' => 'Only jpeg

大家好,我的UploadController中有这样的东西:

$this->validate($request, [
            'covers' => 'required|mimes:jpg,jpeg,png,bmp|max:20000'
        ],[
            'covers.required' => 'Please upload an image',
            'covers.mimes' => 'Only jpeg,png and bmp images are allowed',
            'covers.max' => 'Sorry! Maximum allowed size for an image is 20MB',
        ]);
$input_data = $request->all();
$validator = Validator::make(
   $input_data, [
      'covers.*' => 'required|file|mimes:jpg,jpeg,png,bmp|max:20000'
   ],[
      'covers.*.required' => 'Please upload an image',
      'covers.*.mimes' => 'Only jpg,jpeg,png,bmp images are allowed',
      'covers.*.max' => 'Sorry! Maximum allowed size for an image is 20MB',
     ]);

   if ($validator->fails()) {
     $messages = $validator->messages();
     return redirect()->back()->withErrors($validator);
   }
现在如何在blade中显示警报?我试着这样做:

@if(session()->has('message'))
<div class="alert alert-info alert-dismissible fade show" role="alert">
{{ session('message') }}
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
@endif
但它仅在成功保存更改时显示消息。

回答:


控制器:

$this->validate($request, [
            'covers' => 'required|mimes:jpg,jpeg,png,bmp|max:20000'
        ],[
            'covers.required' => 'Please upload an image',
            'covers.mimes' => 'Only jpeg,png and bmp images are allowed',
            'covers.max' => 'Sorry! Maximum allowed size for an image is 20MB',
        ]);
$input_data = $request->all();
$validator = Validator::make(
   $input_data, [
      'covers.*' => 'required|file|mimes:jpg,jpeg,png,bmp|max:20000'
   ],[
      'covers.*.required' => 'Please upload an image',
      'covers.*.mimes' => 'Only jpg,jpeg,png,bmp images are allowed',
      'covers.*.max' => 'Sorry! Maximum allowed size for an image is 20MB',
     ]);

   if ($validator->fails()) {
     $messages = $validator->messages();
     return redirect()->back()->withErrors($validator);
   }
刀片:

@if ($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert">
   <ul>
   @foreach ($errors->all() as $error)
     <li>{{ $error }}</li>
   @endforeach
   <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
   </button>
   </ul>
</div>
@endif
@if($errors->any())
    @foreach($errors->all()作为$error)
  • {{$error}}
  • @endforeach &时代;
@恩迪夫