0

我正在使用 spaties 媒体库来处理我的图像。我试图允许用户以多部分形式上传图像。

尝试继续时出现此错误

当前请求在名为的键中没有文件pic

它在请求中,就像我执行此操作时一样。

dd($validatedData)

我得到以下 在此处输入图像描述

这是我的控制器功能

  public function postStep2(Request $request){
      $validatedData = $request->validate([
        'pic' => 'required'
      ]);



      if(empty($request->session()->get('user'))){
            $user = new User();
            $user->addMediaFromRequest('pic')->toMediaCollection('profile_image');
            $request->session()->put('user', $user);
        }else{
            $user = $request->session()->get('user');
            $user->addMediaFromRequest('pic')->toMediaCollection('profile_image');
            $request->session()->put('user', $user);
        }


      return redirect('/step3');
    }

这是我的看法

<div class="user-icon--uploader-wrapper">
  <div class="previews"></div>
  <input type="file" name="pic" id="pic">
</div>

这是完整的表格

<form action="/step2" id="signupForm" method="POST" class="register-form" enctype="multipart/form-data">
      {{ csrf_field() }}

      <h4 class="step-heading btn-margin">Step 2 - Verification</h4>


      <div class="input--file youth-photo">
        <h3 class="input--file__title">Photo of Your Passport </h3>
        <div class="user-icon--uploader-wrapper">
          <div class="previews"></div>
          <input type="file" name="pic" id="pic">
        </div>
          <span class="personalphoto">Only a photo of your passport displaying  your photo and information will be permitted.</span>
      </div>


        <div class="input--submit">
          <button type="submit" class="btn-pill--filled complete-step">Go To The Next Step</button>
        <div class="youth-registration__steps-list">
          <p>
            Step 2 of 3 <span>Completed</span>
          </p>
        </div>
      </div>
    </form>
4

1 回答 1

0

将您的默认媒体表迁移文件编辑为:

Schema::create('media', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('model_type');
        $table->uuid('model_id');
        $table->uuid('uuid')->nullable();
        $table->string('collection_name');
        $table->string('name');
        $table->string('file_name');
        $table->string('mime_type')->nullable();
        $table->string('disk');
        $table->string('conversions_disk')->nullable();
        $table->unsignedBigInteger('size');
        $table->json('manipulations');
        $table->json('custom_properties');
        $table->json('responsive_images');
        $table->unsignedInteger('order_column')->nullable();
        $table->nullableTimestamps();
    });
}
于 2020-10-12T09:32:56.087 回答