2017-12-10 1 views
0

행 데이터가 다른 경우 독자가 Excel 파일을 읽지 못하도록하는 방법이 있습니까? 엑셀 파일을 업로드 할 때 Undefined index: 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'),