title: Problem adding fields with multiple images in Laravel
body: <p>How to solve this problem of adding data with uploading multiple images
  This is the frontend code</p>
  <pre><code>&lt;form method=&quot;POST&quot; action=&quot;{{ URL::route('employees.store') }}&quot;  enctype=&quot;multipart/form-data&quot; id=&quot;FormEmployees&quot; class=&quot;Employees&quot;&gt;
      @csrf
  
      &lt;section class=&quot;content&quot;&gt;
      &lt;!-- Main content --&gt;
      &lt;div class=&quot;container&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
  
              &lt;div class=&quot;form-group col-md-2&quot;&gt;
                  &lt;label for=&quot;First_Name&quot;&gt;First Name&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;First_Name&quot; class=&quot;form-control&quot;
                  id=&quot;First_Name&quot; placeholder=&quot;Enter First Name&quot; &gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-2&quot;&gt;
                  &lt;label for=&quot;Last_Name&quot;&gt;Last Name&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;Last_Name&quot; class=&quot;form-control&quot;
                  id=&quot;Last_Name&quot; placeholder=&quot;Enter Last Name&quot; &gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-2&quot;&gt;
                  &lt;label for=&quot;Birth_Date&quot;&gt;Birth Date&lt;/label&gt;
                  &lt;input type=&quot;date&quot; name=&quot;Birth_Date&quot; class=&quot;form-control&quot;
                  id=&quot;Birth_Date&quot;&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-2&quot;&gt;
                  &lt;label for=&quot;Official_Email&quot;&gt;Official Email&lt;/label&gt;
                  &lt;input type=&quot;email&quot; name=&quot;Official_Email&quot; class=&quot;form-control&quot;
                  id=&quot;Official_Email&quot; placeholder=&quot;Enter Official Email&quot; &gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-2&quot;&gt;
                  &lt;label for=&quot;Profile_Photo&quot;&gt;Profile Photo&lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;Profile_Photo&quot; class=&quot;form-control&quot;  required&gt;
              &lt;/div&gt;
  
              &lt;hr style=&quot;width: 100%&quot;&gt;
              &lt;h3&gt;Documents 1&lt;/h3&gt;
              &lt;hr style=&quot;width: 100%&quot;&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;images&quot;&gt;image&lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;images[]&quot; class=&quot;form-control&quot; multiple required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;type&quot;&gt;type&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;type[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;Document_number&quot;&gt;Document number&lt;/label&gt;
                  &lt;input type=&quot;number&quot; name=&quot;Document_number[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;hr style=&quot;width: 100%&quot;&gt;
              &lt;h3&gt;Documents 2&lt;/h3&gt;
              &lt;hr style=&quot;width: 100%&quot;&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;images&quot;&gt;image&lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;images[]&quot; class=&quot;form-control&quot; multiple required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;type&quot;&gt;type&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;type[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;Document_number&quot;&gt;Document number&lt;/label&gt;
                  &lt;input type=&quot;number&quot; name=&quot;Document_number[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
  
  
              &lt;hr style=&quot;width: 100%&quot;&gt;
              &lt;h3&gt;Documents 3&lt;/h3&gt;
              &lt;hr style=&quot;width: 100%&quot;&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;images&quot;&gt;image&lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;images[]&quot; class=&quot;form-control&quot; multiple required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;type&quot;&gt;type&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;type[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;Document_number&quot;&gt;Document number&lt;/label&gt;
                  &lt;input type=&quot;number&quot; name=&quot;Document_number[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
  
              &lt;hr style=&quot;width: 100%&quot;&gt;
              &lt;h3&gt;Documents 4&lt;/h3&gt;
              &lt;hr style=&quot;width: 100%&quot;&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;images&quot;&gt;image&lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;images[]&quot; class=&quot;form-control&quot; multiple required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;type&quot;&gt;type&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;type[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-group col-md-4&quot;&gt;
                  &lt;label for=&quot;Document_number&quot;&gt;Document number&lt;/label&gt;
                  &lt;input type=&quot;number&quot; name=&quot;Document_number[]&quot; class=&quot;form-control&quot; required&gt;
              &lt;/div&gt;
  
              &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;send&lt;/button&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;/section&gt;
      &lt;!-- /.content --&gt;
  
  &lt;/form&gt;
  </code></pre>
  <p>This is the control code</p>
  <pre><code>public function store(Request $request)
  {
      // dd($request-&gt;all());
  
      if ($request-&gt;hasFile('Profile_Photo')) {
          $file_extension = $request-&gt;File('Profile_Photo')-&gt;getClientOriginalExtension();
          $file_name = time() . '.' . $file_extension;
          $path = 'images/Profile_Photo';
          $request-&gt;File('Profile_Photo')-&gt;move($path, $file_name);
      } else {
          $file_name = &quot;default.png&quot;;
      }
  
      $data['Profile_Photo'] = $file_name;
      $data['First_Name'] = $request-&gt;First_Name;
      $data['Last_Name'] = $request-&gt;Last_Name;
      $data['Birth_Date'] = $request-&gt;Birth_Date;
      $data['Official_Email'] = $request-&gt;Official_Email;
  
      $Employee = Employee::create($data);
  
  
      foreach ($request-&gt;type as $Doc) {
  
          $data_Document['employees_id'] = $Employee-&gt;id;
  
          // The error here is: Attempt to read property &quot;type&quot; on string
          $data_Document['Identity_type'] = $Doc-&gt;type;
          $data_Document['Document_number'] = $Doc-&gt;Document_number;
  
          $Document = $Employee-&gt;Document()-&gt;create($data_Document);
  
          // The error here is: Call to a member function file() on string
          foreach ($Doc-&gt;file('images') as $img) {
              $image_name = time() . rand(1, 999) . '.' . $img-&gt;extension();
              $path = 'images/Documentation';
              $img-&gt;move($path, $image_name);
  
              $Employee-&gt;Document()-&gt;Images()-&gt;create([
                  'employees_id' =&gt; $Document-&gt;id,
                  'image' =&gt; $image_name,
              ]);
          }
      }
  
      return redirect()-&gt;route('employees.index')-&gt;with(['success' =&gt; 'Content added successfully']);
  }
  </code></pre>
  <p>This error appears to me
  // The error here is: Attempt to read property &quot;type&quot; on string
  // The error here is: Call to a member function file() on string</p>