Category: Laravel, Laravel, PHP, PHP, MySQL, MySQL

Seeding a database can be done using JSON objects, arrays, and spreadsheets. I had recently come across a situation where I had to seed a MySQL Database using a CSV file in Laravel. During my research, resources were very limited and I had to piece together several pieces of research to arrive at this solution.

Read data from a spreadsheet, append it to an array, and then seeding the database by mapping it to a database model.

Therefore, create a folder called Seeders in the public folder and move your CSV file into it.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners