Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

natcave's avatar
Level 10

Laravel database seeding with real street addresses

Hey there. Laravel newbie here, having lots of fun learning. I'm building a store locator app. I was excited to learn that faker will generate fake street addresses. Awesome! However, when I tried map the results I quickly learned the addresses were not real. The latitude, longitude, postal codes, states, cities, and street addresses do not relate to one another, they are randomly put together. This would work great for a shopping cart app that needs shipping information, but for geocoding I need real street addresses. Any suggestions?

Here is my ModelFactory.php file

0 likes
7 replies
mstnorris's avatar

Just find a list of street addresses and insert them into the database. There are plenty available after a little searching.

In anywise, if the map is working... Just displaying a weird location, it doesn't matter right? It works.

natcave's avatar
Level 10

Thanks mstnorris. I see now that I don't have to use the faker, I can just replace it with an insert statement. Cool. I thought it would be nice to pull in random real addresses, just wondering if anyone else ran into this scenario and found an answer. In the meantime, I'll set it up manually. Thanks for your quick answer.

simondavies's avatar

Or you can do them yourself.

So using google maps for example, select a country say: UK.

Select about 20 cities, then zoom into these and then select a street within these cities, then note down the street name, city/town, county, county, then also make a note of its geo location data.

Then add these in to the db to play with.

natcave's avatar
Level 10

Thanks @simondavies, I will do exactly that to grow the existing data.

I tried a few other options that didn't pan out. However, I did a little more digging and found this sweet function:

DB::unprepared(File::get($file));

This function imports a database export file. So now I can export my database test table and save it in a folder within the project. Then ad this code to the migration file and it will pull the last export data right back in, instead of having to regenerate new fake data. Pretty cool.

I still would like to find a function that will create random real addresses but this is the next best thing.

Thanks so much for your help guys. If anyone stumbles on a solution, feel free to drop a line on this thread. Since I'm a newbie I won't be far. :-)

stuart@yonder.co.za's avatar

I know this is an old thread, but I created a Laravel library for this. Check it out:

https://github.com/nonsapiens/addressfactory

This generates actual, real world street addresses (along with Google Maps geodata) for you to use in DB seeding, testing, or anything you like. I originally built this for a GPS location app I was writing.

2 likes
xs2ahmed's avatar

@stuart@yonder.co.za [email protected] Hi, I came on this page searching to get a library for real addresses with lon lat, I tried your library but it fails to work. I have followed all your instructions on your github page, I get the error below, when I try to called $faker->britishAddress(); can you kindly help ?? I am new to php and laravel

I am using Laravel Framework 6.4.1

Symfony\Component\Debug\Exception\FatalThrowableError : Call to undefined function Yomo\AddressFactory\kebab_case()

at C:\xampp\htdocs\finder\vendor\yomo\addressfactory\src\RealAddress.php:139 135| { 136| 137| $this->addresses = collect(); 138|

139| if ( $cnfCountry = Config::get( 'realaddress.' . kebab_case( $country ), false ) ) { 140| 141| if ( is_null( $locations ) ) $locations = $cnfCountry[ 'cities' ]; 142| if ( is_string( $locations ) ) $locations = [ $locations ]; 143|

Exception trace:

1 Yomo\AddressFactory\RealAddress::make("GreatBritain") C:\xampp\htdocs\finder\vendor\yomo\addressfactory\src\RealAddress.php:111

2 Yomo\AddressFactory\RealAddress::makeBritain() C:\xampp\htdocs\finder\vendor\yomo\addressfactory\src\Faker\RealAddress.php:28

Please or to participate in this conversation.