https://github.com/Maatwebsite/Laravel-Excelこのパッケージを使用しています。そして、ファイルをアップロードすると、 dd(result) は
CellCollection {#842 ▼
#title: null
#items: array:4 [▼
"news_title" => "7th AGM of ADBL today; endorsing 47% cash"
"desc" => "The AGM will be endorsing 47% percent cash dividend to its shareholders from the net profit it earned in last fiscal year 2070/71. "
"link" => "http://www.sharesansar.com/viewnews.php?id=26224&cat=news"
"stock_code" => "LBL"
]
}
したがって、ここでは #items にデータが含まれていますが、 #title が出力される理由はわかりません。データを保存しようとすると、#title が原因で Integrity Violation エラーが発生します。それで、解決策はありますか?
ここにデータを保存するための私のコードがあります
public function excelNews()
{
if (Input::hasFile('file')) {
$file = Input::file('file');
Excel::load($file, function($reader) {
$reader->setDateFormat('j/n/Y H:i:s');
$results = $reader->get();
foreach ($results as $result)
{
dd($result); // for testing
$news = new StockNews;
$news->title = $result->news_title;
$news->desc = $result->desc;
$news->save()
}
});
}
Flash::success('News has been successfully updated');
return redirect::back();
}
エラーメッセージ
整合性制約違反列 'title' は null にできません