0

I'm using spaties media library to handle my images. I'm trying to allow a user to upload images in a multipart form.

I'm getting this error when trying to progress on

The current request does not have a file in a key named pic

It's in the request, as when I preform this.

dd($validatedData)

I get the following enter image description here

This is my controller function

  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');
    }

This is my view

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

This is the full form

<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>
apokryfos
  • 38,771
  • 9
  • 70
  • 114

1 Answers1

0

Edit your default media table migration file to:

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();
    });
}
Shumon Pal
  • 314
  • 3
  • 12