In this episode, we're getting all set up with some sample data so we can play around with CSV importing later on. First, we create a new Customer
model, set up the migration for the customers table, and make sure to include all the fields we might need (like first name, last name, email, company, VIP status, and birthday). We pay special attention to things like making emails unique (since that's important for importing!) and thinking about which fields can be nullable.
Once the migration is done, we move on to factories. Here, we define what fake data should look like for our customers—random names, unique emails, sometimes a company, and some sensible defaults for the other fields. This lets us easily generate a batch of test users.
After that, we use php artisan tinker
to actually generate (seed) 100 fake customers and push them into the database. Then, we look at how to export all that data as a CSV file—just using our database tool (like Postico), selecting the records, and saving them out. Now we've got a CSV with realistic customer data, ready to test importing (and re-importing) back into our table.
By the end of this episode, we've got sample data and a CSV file prepped and ready to go for the next step: building out the CSV importer itself!