2017-12-10 4 views
0

行データが異なる場合、読者がExcelファイルを読み込まないようにする方法はありますか?私がExcelファイルをアップロードすると、Undefined index: descriptionが得られます。つまり、descriptionがアップロードされたファイルに見つかりません。定義されていないインデックス:description - Excelファイルのアップロード

このエラーを処理できる方法はありますか? (!$行[ '説明']):

if ($request->file('imported-file')) { 
    $path = $request->file('imported-file')->getRealPath(); 

    $data = Excel::load($path, function($reader) { 
    $reader->calculate(false); 
    })->get(); 

    if (($request->file('imported-file')->getClientOriginalExtension()) != 'xlsx') { 
    return redirect('')->with('error','File Format may not be supported'); 
    } else { 

    if (!empty($data) && $data->count()) { 
     foreach ($data->toArray() as $row) { 
      if (!empty($row)) { 
      $dataArray[] = [ 
       'name' => $row['name'], 
       'description' => $row['description'], 
      ]; 
      } 
     } 

     if (!empty($dataArray)) { 
     Item::insert($dataArray); 

     return redirect('')->with('status','successfully added'); 
     } 
    } 

    } 
} 
+0

'場合に使用することができます – Tpojka

答えて

1

の代わりに、 `{}ブレーク

'description' => $row['description'], 

あなたは

'description' => array_get($row, 'description'), 
関連する問題