In this episode, we look at how to control which columns from your CSV you actually want to import—because sometimes, you don’t need, or want, every column.
We start by heading to our customers index where the CSV importer is used and introduce a new property, columnsToMap
. This is an array that lets us specify just the columns we care about, like id
, first_name
, last_name
, and email
. You can always add more later, but keeping it simple lets you see how the process works.
Then, inside the CSV Importer component, we set up columnsToMap
as a public property, and show how to transform it so each field (like id
or email
) becomes a key in a new array, with an empty value ready to be mapped later. This structure makes it easy to line up which CSV headers should match which database columns.
We use a Laravel collection to do the array transformation, making sure each column is ready for the dropdowns in our mapping UI. After a quick test dump, you’ll see the array structure is looking good—all set up for mapping.
That’s pretty much everything needed for mapping the columns! In the next video, we’ll actually build the UI to let users select which header goes with which column. See you there!