定制 piyook/csvseeder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

piyook/csvseeder

Composer 安装命令:

composer require piyook/csvseeder

包简介

Seed data into Laravel DB tables from .csv files

README 文档

README


CSV Database Seeder Utility Service

A simple Laravel utility package to seed database tables with CSV data.
Explore the docs »

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contact


About The Project


A simple utility for Laravel that allows a database to be quickly populated using data from a file in CSV format.

A custom Artisan make: command builds the CSV seeder class which then imports data from a CSV file stored in database/data folder.

Built With

  • Laravel 9

Getting Started


The code can be added to a fresh Laravel install or an existing project.

Prerequisites

Laravel 8+

Installation


Install the package using composer

    composer require --dev piyook/csvseeder

Usage


A custom Artisan make command was developed to make scaffolding a Seeder Class to import CSV files easier.

The CSV data file must share the same name as the table and be stored in a database/data folder.

To use the Artisan command simply type :

 php artisan make:csvseeder <name> <columns> <path> (optional)

Where the table name to be seeded is passed to the make command along with an ARRAY of column names [].
Note that if the table name is plural then the singular form will be used for the class name

If the seeder class is to be stored in a location OTHER than database/seeders then you can specify this new path as the final option.

E.g A new Seeder Class for a table called "examples" which will import from the "examples.csv" file held in database/data, will be saved to the database/seeders directory with the filename "ExampleCSV.php".


  php artisan make:csvseeder examples [col1,col2,col3,col4]

then

php artisan migrate:fresh

php artisan db:seed --class=ExampleCSV

DONT FORGET TO REGISTER THE NEW CSV SEEDER IN THE DatabaseSeeder CLASS IN THE SEEDERS FOLDER BEFORE RUNNING A GENERAL DB SEED AS PART OF A MIGRATION WITH THE --SEED OPTION

Testing


Orchestra Testbench would normally be used to run unit and feature tests in the package but the seeder function would not work (the seeder class was not found).

A full seperate Laravel test project was set-up and the tests, phpunit.xml and the database/data, database/migration folders and files in the package test folder copied into the relevant places in the project to set up the test environment.

All Feature tests work running with Artisan test command.

Contact


Email: piyook@piyook.com

Project Link: [laravelcsvseed]

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固