标签:util try file created demo service reac esc 成功
1、laravel Excel批量导入数据到DB
<?php namespace App\Http\Controllers\Module; use App\Http\Controllers\Controller; use App\Models\ModuleInterface; use App\Services\Util\Msg; class ImportController extends Controller { /** * Excel批量导入数据到DB * @return \Illuminate\Http\JsonResponse */ public function index() { try { $file = ‘demo.xls‘; Excel::load($file, function($reader) { $sourceData = collect($reader->get())->toArray(); $insertData = []; $dateTime = date(‘Y-m-d H:i:s‘, time()); foreach ($sourceData as $key => $item) { $insertData[] = [ ‘Fname‘ => $item[‘fname‘], ‘Fdescribe‘ => $item[‘fdescribe‘], ‘Fservice_id‘ => (int)$item[‘fservice_id‘], ‘Fbusi_person‘ => ‘tayloryu‘, ‘Fdevops‘ => ‘tayloryu‘, ‘Fcreated_at‘ => $dateTime, ‘Fcreator‘ => ‘tayloryu‘, ]; } ModuleInterface::insert($insertData); }); return Msg::out(‘导入成功!‘); } catch (Exception $e) { return Msg::out($e->getMessage(), $e->getCode()); } } }
标签:util try file created demo service reac esc 成功
原文地址:https://www.cnblogs.com/huqi21st/p/8854954.html