simonhamp / laravel-nova-csv-import

The best CSV import component for Laravel Nova
https://novapackages.com/packages/simonhamp/laravel-nova-csv-import
MIT License
168 stars 76 forks source link

Prevent duplicates #70

Closed HeadStudios closed 1 year ago

HeadStudios commented 1 year ago

How should I modify my code to prevent duplicates (based on email column of Contact model) when importing through CSV and ideally showing error on frontend? Below is my attempts so far: https://chat.openai.com/share/aa72b7fb-fb5f-432c-b295-a2e68c3e61fd

Thank you!

simonhamp commented 1 year ago

That's a lot to run through 😅

Having not investigated the full history of your ChatGPT session, I want to indicate that I believe CSV Import already supports what you're trying to achieve; you shouldn't need to change any code within the package to do what you're trying to do here

Your resource and database just need to be set up correctly:

  1. Add a unique validation rule to your email field in your Nova Resource definition
  2. OPTIONAL (but highly recommended): Add a UNIQUE index to your email column

The import summary in the latest versions of CSV Import should provide you with enough detail to know what has happened:

HeadStudios commented 1 year ago

Thank you so much!

simonhamp commented 1 year ago

Glad I could help @HeadStudios 👍🏼