I'm looking to add a table of countries to a project I'm building. For testing, i just made a migration and added a handful of countries manually. I imagine there's something out there that I could just import into my project that would add all the countries of the world. I don't need anything fancy like currencies and languages - just a list of countries with ISO codes. Any suggestions?
To add a list of countries with ISO codes to your Laravel project, you can use a package or seed your database with a predefined list. Here's a simple approach using a seeder:
Create a Migration for the Countries Table:
First, create a migration for the countries table:
If you prefer using a package, you can consider using webpatser/laravel-countries, which provides a comprehensive list of countries with ISO codes. You can install it via Composer:
composer require webpatser/laravel-countries
Then, publish the configuration and run the migration provided by the package:
That was sort of helpful. The first part about seeding the table is essentially what I already did. I'm hoping to find a source for all countries of the world without having to add them all manually (either in a seeder or directly in the table). The second part is what I was looking for but this package seems pretty old. I was able to install the package but nothing past that. I just got a message 'No publishable resources for tag [].' when I tried to publish the configuration. I'll keep looking, I guess.
Use ChatGPT, depending on your subscription. Ive found it to be very good for dumb work, especially making seeders.
So, you can start a chat with a small sample and then ask it to fill it fully out for you in a file. It would build a file using python and then send you a complete custom DB seeder. You can even attach it files in the chat to use as references, if you want something specific.
Then what you should also do is start a new chat, send the previously generated countries file (From the prev ChatGPT chat) and ask the new ChatGPT to proof it and tell it theres countries missing and to find out which ones, and it will actually double check. Try to fool it, and never give in on a first attempt, cos it can make mistakes, so you need to ask it to double check by fooling it.
Create a seeder with ChatGPT, just ask him to do it. Do not forget to specify the fields you need. I've done it several times, it's very useful for these things
Thanks for the suggestion of ChatGPT. I hadn't thought of that but tried it. It took a couple tries, but in the end I got a good table that suits my needs. Much simpler than the package I had tried initially.