PHP知识点草稿
Posted 风中凌乱的猫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP知识点草稿相关的知识,希望对你有一定的参考价值。
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()); } } }
以上是关于PHP知识点草稿的主要内容,如果未能解决你的问题,请参考以下文章