Seed Countries in Laravel App | How to Add Country List in Laravel? | Seed Countries in Databse

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back the today video is about to see the phone number with their countries into the database so you can see to these countries in your any type of application so i'm doing this with the laravel so let's start it so this question asked 11 years ago and someone answered this in the json permit right so now we are going to insert these countries into our database so let's go to the larval project and here you need to create to first reader and then we will see these countries into our database so let's create first let me create a model and a table right so it's a php artisan make model and the model name is country okay and i want to also create a migration so i'm adding the uh migration flag here so model is created yes this one okay and let's go to the database and do and and yes this is also going to create in a few seconds so let's wait for a moment to complete this process and yes it's completed successfully so now we need to migrate this table into our database artisan migrate okay so it will make the last table okay yes it's migrated so let's go to the database and check that is it migrated or not so give it a refresh and [Music] yes this table is negated here right so oh i forgot to add a column here so let me roll back this last migration so php altison migrate and roll back so if you don't familiar with this roll back a specific migration so can you can watch my previous videos where i explain that how you we can roll back a specific migration so i'm also creating this uh string because um some country codes having some samples like plus and stuff like that i'm making this code right save this one and now let's migrate this if we altern migrate hit enter and yes it's migrated so let's clear it and now we need to create a countryside so let's create a seeder php artisan make make cedar and the seater name would be the country seeder okay hit enter and it will create seeder for us yes let's go to the database nut cedar uh yes seeder and there is a countryside all right so here we need to execute our array file right so first i want to truncate to the table for let me make this table and our table name is countries countries okay let me type this countries and i want to truncate it right so if there is any entries it will first remove the entries and then recreate recreate from this line okay so let's go here and you need to copy this all of this stuff but this is in the json format so we need this in the array format so i converted this into an array here right so you can grab this file from there file entries not file so you can also get this file from the from using a storage get method so you can get this file and you can get the file content so i'm copying this from this file this is a this is in array format so i will add this so in the description so you can also get this file and see though the countries into your database so it's very simple oops okay let's copy this go to the seeder file and here you need to create a variable of countries oops okay and then to go to the next line and here you need to paste this all of the stuff okay and then this is an array so you need to save this array so in our case it's a model name is country oops country and then you need to make this insert because we are inserting multiple records so insert will add multiple use to add multiple record into the database so create will not work for this situation right so this will insert the data into the database so now for now our database is empty right so let me give it a refresh and yes name and code is there so here we need to run our seeder so the command is php artisan db seed baby seed and then you need to call your seeder so class our class name is this one right so it's a country seeder and hit enter and yes it says database reading completed successfully so let's hit refresh and yes it's so seeded the name and their code into the database so you can search their name so i'm searching my country code and this name so my country is pakistan and yes pakistan get the code is this one so it's exactly what we are looking for so i'm for i get this json from there and i converted this into an array format and then i'm i follow this blog it's very uh very clear right so first you need to create your project then you need to create a migration right and then you can create a seeder here and i did not use this because in our case i'm using the country code not this country uh country code like in this string format so that's why because i want to send a sms to each number so that's why i use this code here so other otherwise i will use this uh array right so then how you can get this you can get this i'm not i'm doing this in the seeder so you can do this in your controller so here you can use a plug method and get only name and the code from the database so that is the beauty of this block method so hopefully you unders understood the concept so if you are interested to learn more about laravel subscribe the youtube channel and stay connected bye
Info
Channel: Career Development Lab
Views: 3,428
Rating: undefined out of 5
Keywords: laravel, laravel course, laravel beginners course, laravel advance course, laravel with cdl, career development lab, cdl, laravel with hadi, laravel guide, https://cdlcell.com, cdlcell, seed countries in laravel, how to add countries in laravel db, seed all countries in laravel, import countries list in laravel, How to Add Country List in Laravel
Id: s2LoSl8ncAk
Channel Id: undefined
Length: 7min 7sec (427 seconds)
Published: Tue Mar 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.