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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners