title: photo upload code does not work and for the code that already worked before
body: <p>i need to upload a photo, the file the information comes from the view in an array with more values of other variables, but the upload code is not working. without this code the rest works perfectly, when I add the upload code nothing works.
  help please</p>
  <pre><code>public function CreateProduction(Request $request)
      {
          $data = $request-&gt;all();
          
          
          $production = new production;
          $production-&gt;status = 1;
          $production-&gt;done = 0;
          $production-&gt;save();
          $production_id = DB::getPdo()-&gt;lastInsertId();
          
  
          $proposal = proposal::where('id_proposal', $data['id_proposal'])-&gt;first();
          $proposal-&gt;id_production = $production_id;
          $proposal-&gt;save();
          $proposedphases = $proposal-&gt;proposed_phases()-&gt;get();
          
  
          foreach($proposedphases as $proposedphase)
              {
                  $this-&gt;validate($request, [
                      'select_file'  =&gt; 'required|image|mimes:jpg,jpeg,png,gif|max:200000'
                     ]); 
                
                     $image = $request-&gt;file('select_file');
                
                     $new = rand() . '.' . $image-&gt;getClientOriginalExtension();
                     
                
                     $image-&gt;move(public_path('images'), $image);
  
                  $productionphase = new production_phases;
                  
                     $productionphase-&gt;photo = $new;
                  $color_cap_out = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'cap_out'])-&gt;first();
                      {
                          $productionphase-&gt;cap_out_id = $color_cap_out['id_color'];
                          $productionphase-&gt;cap_out_name = $color_cap_out['name'];
                          $productionphase-&gt;cap_out_code = $color_cap_out['code'];
                      }
                  $color_cap_in = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'cap_in'])-&gt;first();
                      {
                          $productionphase-&gt;cap_in_id = $color_cap_in['id_color'];
                          $productionphase-&gt;cap_in_name = $color_cap_in['name'];
                          $productionphase-&gt;cap_in_code = $color_cap_in['code'];
                      }
                  $color_cord = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'cord'])-&gt;first();
                      {
                          $productionphase-&gt;cord_id = $color_cord['id_color'];
                          $productionphase-&gt;cord_name = $color_cord['name'];
                          $productionphase-&gt;cord_code = $color_cord['code'];
                      }
                  $color_ribe_corp = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'ribe_corp'])-&gt;first();
                      {
                          $productionphase-&gt;ribe_corp_id = $color_ribe_corp['id_color'];
                          $productionphase-&gt;ribe_corp_name= $color_ribe_corp['name'];
                          $productionphase-&gt;ribe_corp_code = $color_ribe_corp['code'];
                      }
                  $color_ribe_arm = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'ribe_arm'])-&gt;first();
                      {
                          $productionphase-&gt;ribe_arm_id = $color_ribe_arm['id_color'];
                          $productionphase-&gt;ribe_arm_name = $color_ribe_arm['name'];
                          $productionphase-&gt;ribe_arm_code = $color_ribe_arm['code'];
                      }
                  $color_bibo = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'bibo'])-&gt;first();
                      {
                          $productionphase-&gt;bibo_id = $color_bibo['id_color'];
                          $productionphase-&gt;bibo_name = $color_bibo['name'];
                          $productionphase-&gt;bibo_code = $color_bibo['code'];
                      }
                  $color_zip = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'zip'])-&gt;first();
                      {
                          $productionphase-&gt;zip_id = $color_zip['id_color'];
                          $productionphase-&gt;zip_name = $color_zip['name'];
                          $productionphase-&gt;zip_code = $color_zip['code'];
                      }
                  $color_mola = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'mola'])-&gt;first();
                      {
                          $productionphase-&gt;mola_id = $color_mola['id_color'];
                          $productionphase-&gt;mola_name = $color_mola['name'];
                          $productionphase-&gt;mola_code = $color_mola['code'];
                      }
                  
                  if($data[$proposedphase-&gt;id_proposedphase.'arm'] == 0)
                      {
                          $productionphase-&gt;arm_name = 'normal';
                      }
                  if($data[$proposedphase-&gt;id_proposedphase.'arm'] == 1)
                      {
                          $productionphase-&gt;arm_name = 'reglan';
                      }
                  $productionphase-&gt;material = $data[$proposedphase-&gt;id_proposedphase.'material'];
                  $productionphase-&gt;id_production = $production_id;
                  $productionphase-&gt;id_proposedphase = $proposedphase['id_proposedphase'];
                  
                     
                  $productionphase-&gt;save();
                  $productionphase_id = DB::getPdo()-&gt;lastInsertId();
                   
                  if ( $data[$proposedphase-&gt;id_proposedphase.'corp_color_1'] !=0)
  
                      {
                          $color_1 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'corp_color_1'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 0;
                          $production_phase_colors-&gt;id_color = $color_1['id_color'];
                          $production_phase_colors-&gt;name = $color_1['name'];
                          $production_phase_colors-&gt;code = $color_1['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
                  
                  if ( $data[$proposedphase-&gt;id_proposedphase.'corp_color_2'] !=0)
  
                      {
                          $color_2 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'corp_color_2'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 0;
                          $production_phase_colors-&gt;id_color = $color_2['id_color'];
                          $production_phase_colors-&gt;name = $color_2['name'];
                          $production_phase_colors-&gt;code = $color_2['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
  
                  if ( $data[$proposedphase-&gt;id_proposedphase.'corp_color_3'] !=0)
  
                      {
                          $color_3 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'corp_color_3'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 0;
                          $production_phase_colors-&gt;id_color = $color_3['id_color'];
                          $production_phase_colors-&gt;name = $color_3['name'];
                          $production_phase_colors-&gt;code = $color_3['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
  
                  if ( $data[$proposedphase-&gt;id_proposedphase.'arm_color_1'] !=0)
  
                      {
                          $color_1 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'arm_color_1'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 1;
                          $production_phase_colors-&gt;id_color = $color_1['id_color'];
                          $production_phase_colors-&gt;name = $color_1['name'];
                          $production_phase_colors-&gt;code = $color_1['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
                  
                  if ( $data[$proposedphase-&gt;id_proposedphase.'arm_color_2'] !=0)
  
                      {
                          $color_2 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'arm_color_2'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 1;
                          $production_phase_colors-&gt;id_color = $color_2['id_color'];
                          $production_phase_colors-&gt;name = $color_2['name'];
                          $production_phase_colors-&gt;code = $color_2['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
                      
                  if ( $data[$proposedphase-&gt;id_proposedphase.'arm_color_3'] !=0)
  
                      {
                          $color_3 = color::where('id_color', $data[$proposedphase-&gt;id_proposedphase.'arm_color_3'])-&gt;first();
                          $production_phase_colors = new production_phase_colors;
                          $production_phase_colors-&gt;part = 1;
                          $production_phase_colors-&gt;id_color = $color_3['id_color'];
                          $production_phase_colors-&gt;name = $color_3['name'];
                          $production_phase_colors-&gt;code = $color_3['code'];
                          $production_phase_colors-&gt;id_productionphase = $productionphase_id; 
                          $production_phase_colors-&gt;save();
                      }
  
                  $proposedphasesizes = $proposedphase-&gt;proposedphasesizes()-&gt;get();
  
                  foreach($proposedphasesizes as $proposedphasesize)
                      {
                          $productionphasesize = new production_phase_size;
                          $productionphasesize-&gt;id_size = $proposedphasesize['id_size'];
                          $productionphasesize-&gt;name = $proposedphasesize['name'];
                          $productionphasesize-&gt;quantity = $proposedphasesize['quantity'];
                          $productionphasesize-&gt;done = 0;
                          $productionphasesize-&gt;id_productionphase = $productionphase_id;
                          $productionphasesize-&gt;save();
                          
                      }
  
                  
              }
              $production = production::where('id_production', $production_id)-&gt;first();
  
                      $logs = new logs;
                      $logs-&gt;id_user = Auth::user()-&gt;id_user;
                      $logs-&gt;name = Auth::user()-&gt;name;
                      $logs-&gt;description = &quot;criada nova produção&quot;;
                      $logs-&gt;save();
  
              return view('admin.production.list_productions', compact('production'));  
      }
  </code></pre>
  <p>here is the complete controller for analysis as requested, I continue to say that without the upload code that is right after opening the foreach the rest works perfectly, but with this piece it stops working</p>