title: "Undefined index: name" Laravel 5.7 Controller
body: <p>I'm new to the blog and I joined because I have a problem for a while.</p>
  
  <p>The following code is for importing users through a .csv file into a database, but when I try to import users, the following error appears.</p>
  
  <pre><code>8
  "Undefined index: name"
  "D:\xampp\htdocs\plataforma\app\Http\Controllers\UserController.php"
  39
  array:7 [▼
    "request" =&gt; Request {#43 ▶}
    "validator" =&gt; Validator {#257}
    "file" =&gt; UploadedFile {#247 ▶}
    "csvData" =&gt; """
      name,username,email,password,role,idSede,idManager\r\n
      Claudio Magallan,claudiomg,claudiomagallan@hotmail.com,secret,2,60,0\r\n
      Cristina Vargas,cristyvg,cristyvargas@institutodeventas.com,secret,3,61,4\r\n
      """
    "rows" =&gt; array:3 [▶]
    "header" =&gt; array:7 [▶]
    "row" =&gt; array:7 [▶]
  ]
  </code></pre>
  
  <p>I really appreciate your help and I hope you can help with my problem.
  I attach my controller code.</p>
  
  <pre><code>public function upload(Request $request) {
    $validator = Validator::make($request-&gt;all(), [
      'file' =&gt; 'required'
    ]);
    if ($validator-&gt;fails()) {
      return redirect()
      -&gt;back()
      -&gt;withErrors($validator);
    }
    $file = $request-&gt;file('file');
    $csvData = file_get_contents($file);
    $rows = array_map("str_getcsv", explode("\n", $csvData));
    $header = array_shift($rows);
    foreach ($rows as $row) {
      $row = array_combine($header, $row);
      User::create([
        'name' =&gt; $row['name'],
        'username' =&gt; $row['username'],
        'email'    =&gt; $row['email'],
        'password' =&gt; bcrypt($row['password']),
        'role'     =&gt; $row['role'],
        'idSede'   =&gt; $row['idSede'],
        'idManager'=&gt; $row['idManager'],
      ]);
    }
    flash('Users imported');
    return redirect()-&gt;back();
  }
  </code></pre>
  
  <p>The error mark the next line code:</p>
  
  <blockquote>
    <p>'name' => $row['name'],</p>
  </blockquote>
  
  <p>Regards!</p>