Upload CSV file and import it to database using Laravel

前端 未结 2 677
温柔的废话
温柔的废话 2020-12-16 07:42

I have this method that uploads a file of a CSV format, but now i want to know how to upload it into columns in my database.

My method:

 public funct         


        
2条回答
  •  遥遥无期
    2020-12-16 08:05

    While load data infile is the quickest way, I prefer to use a lib like https://github.com/ddeboer/data-import or https://github.com/goodby/csv for 2 reasons.

    1. It is extensible, what if your data source changes to excel files or a mongo db or some other method?

    2. It is mallable, if you need to convert dates, or strings or numbers you can do it conditionally which cannot be done with a batch command.

    my 2c

提交回复
热议问题