Assume we have a customers table and there is a field like a customer address. Now we want to seed data in laravel using database seeder to generate some fake addresses for customers. To do that, we can use address helper. I will show you the example of laravel faker street address.

So if you are looking for laravel factory faker address then this tutorial is for you. So let's see the example code of laravel faker address:

<?php

use App\Models\Customer;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;

class CustomerSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $faker = Faker::create();

        for ($i=1; $i < 101 ; $i++) { 
            $customer = new Customer;
            $customer->address = $faker->address;
            $customer->save();
        }  
    }
}

 

If you are in Laravel 9 version, then you can use like this:

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class CustomerFactory extends Factory
{
    public function definition()
    {
        return [
            'address' => fake()->address()
        ];
    }
}

 

See all the available faker address helper from below:

secondaryAddress                    // 'Suite 961'
state                               // 'NewMexico'
buildingNumber                      // '484'
city                                // 'West Judge'
streetName                          // 'Keegan Trail'
streetAddress                       // '439 Karley Loaf Suite 897'
address                             // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
country                             // 'Falkland Islands (Malvinas)'

 

Read also: Laravel Faker Phone Number Example

 

Conclusion

I have tried to discuss the clear concept of laravel faker street address. Now we know laravel factory faker address. Hope this laravel faker address tutorial will help you.