laravel5.4 关于数据填充的知识

news/2024/7/5 2:32:04

需求:大量excel表格数据 集中整理到一个规定数据表中,并且增加新字段做标记
步骤:把需要整理的excel表格提前存放到mysql数据库指定的表中 ,可以用图形化工具来执行!

核心:利用laravel5.4 框架自带的填充功能, 填充类都位于 database/seeds 具体可看文档操作

基于以上需求:直接上代码
<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**

  • Run the database seeds.
  • @return void
    */
    public function run()
    {
    // $this->call(UsersTableSeeder::class); //也可以以这样的形式来执行
    //每50条遍历一次 296_copy是excel表存进数据库里的新表名
    DB::table('296_copy')->orderBy('id')->chunk(50,function($result){
    foreach($result as $val){
    //car 目的表
    DB::table('car')->insert(
    [
    '字段' => $val->遍历插入的数据,
    //增加字段插入
    'sign1' => 'CKG',

                        ]);}});

    }
    }

利用phpstrom编辑器 进行命令行操作:Terminal窗口 进入laravel项目
执行命令:
php artisan db:seed

转载于:https://blog.51cto.com/kangjunfei/2059510


http://lihuaxi.xjx100.cn/news/239178.html

相关文章

6.1.1 验证注解的使用

数据注解特性定义在名称空间System.ComponentModel.DataAnnotations 中(但接下来 将看到&#xff0c;有些特性不是定义在这个名称空间中)。它们提供了服务器端验证的功能&#xff0c;当在模 型的属性上使用这些特性之一时&#xff0c;框架也支持客户端验证。在名称空间DataAnno…

香草 jboss 工具_香草JavaScript中的记忆游戏

香草 jboss 工具by Marina Ferreira通过玛丽娜费雷拉(Marina Ferreira) 香草JavaScript中的记忆游戏 (Memory Game in Vanilla JavaScript) 在30分钟内构建一个记忆游戏&#xff0c;学习JS&#xff0c;CSS和HTML&#xff01; (Learn JS, CSS and HTML by building a memory ga…

织梦 新建 php arclist,织梦arclist按照自定义字段来调用相关文章

织梦arclist按照自定义字段来调用相关文章&#xff0c;这对于想要在首页调用某个自定义字段的文章的同学来讲&#xff0c;非常不错&#xff0c;接下来看教程打开 include aglibrclist.lib.php 找到&#xff1a;//时间限制(用于调用最近热门文章、热门评论之类)&#xff0c;这里…

CES上百度无人车队炫技,陆奇要用“China speed”改变世界

本文由 「AI前线」原创&#xff0c;原文链接&#xff1a;CES上百度无人车队炫技&#xff0c;陆奇要用“China speed”改变世界编辑&#xff5c;EmilyAI 前线导读&#xff1a;“美国当地时间 1 月 8 日&#xff0c;百度在拉斯维加斯举办了主题为“AI is Changing the World, Chi…

卸载linux系统装win,如何在计算机上删除 Linux 并安装 Windows

多个 IDE 驱动器Device Boot Start End Blocks Id System/dev/hda1 * 1 500 4016218 83 Linux native (IDE hard drive 1, partition 1)/dev/hda2 501 522 176715 82 Linux swap (IDE hard drive 1, partition 2)/dev/hdb1 1 500 4016218 83 Linux native (IDE hard drive 2, p…

latex 插图解释_大O符号-只需插图和视频即可解释

latex 插图解释Big O notation is used to communicate how fast an algorithm is. This can be important when evaluating other people’s algorithms, and when evaluating your own! In this article, I’ll explain what Big O notation is and give you a list of the m…

IntelliJ IDEA控制台输出中文乱码问题解决

如果还不行&#xff0c;那么再极端的设置&#xff0c;在IDEA启动的时候强制设置为UTF-8&#xff1a; 打开增加-Dfile.encodingUTF-8&#xff0c;重启Intellij IDEA 再或者直接在项目运行的时候加入UTF-8的设置 如果还是不行&#xff0c;那么你可能装了一个假的IDEA。