0
我正在更新並從文件插入到DB中的3個表中。我想檢查一切是否正常,如果沒有錯誤發生,以便我可以向用戶顯示成功消息,如果上傳成功了。我怎樣才能做到這一點?Laravel 5.4 - 檢查所有模型插入和更新是否正常
這是我的代碼:
public function upload(Request $request)
{
if ($request->hasFile('csvFile')) {
$file = $request->file('csvFile');
$file->move('uploads', $file->getClientOriginalName());
$this->store($file);
}
Session::flash('flash_message','File was successfully uploaded.');
return view('home');
}
public function store($file)
{
$path = base_path('public/uploads/' .$file->getClientOriginalName());
$rows = Excel::load($path, function($reader) { })->get()->toArray();
foreach($rows as $row) {
$id = $row[4];
$shopeTitle = $row[1];
$price = $row[6];
$mall = $row[5];
$visitors = $row[3];
Shop::updateOrCreate(
['id' => $id],
['title' => $shopeTitle]
);
Mall::where('id', $id)->update([
'price' => $price,
'visitors' => $visitors
]);
if ($mall != 41 || $mall!= 42) {
DB::table('store_mall')->insert([
'mall' => $price,
'store' => $id
]);
}
}
}