# Membuat data dummy dengan factory di Laravel

Last edited time: June 7, 2023 7:35 AM Owner: Indry Sefviana Tags: Laravel

<figure><img src="https://3397141630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVUQUm1GVUT3pDnRHmDRU%2Fuploads%2Fz8FZuqFINZsxqhnowxex%2FUntitled%20(9).png?alt=media&#x26;token=a0769d50-2be9-458d-92a1-ba0a512fa3e3" alt=""><figcaption></figcaption></figure>

Langkah awal membuat data dummy dengan factories di Laravel

buat seeder terlebih dahulu

```
php artisan make:seeder MemberSeeder
```

cek pada file `database\seeders\MemberSeeder.php`, copycat code berikut

```
public function run()
    {
        factory(App\Member::class, 10)->create();
    }
```

Buat factory dengan code berikut

```
php artisan make:factory model=MemberFactory --model=Member

```

Lalu pastekan code berikut pada `database\factories\MemberFactory.php`

```
public function definition()
    {
        return [
            'name' => $this->faker->name(),
            'email' => $this->faker->unique()->safeEmail(),
	    'address' => $this->faker->secondaryAddress(),
        ];
    }
```

Untuk data dummy lainnya bisa di cek disini [fzaninotto/Faker](https://github.com/fzaninotto/Faker)

Kemudian jalankan seeder pada terminal dengan code berikut

```
php artisan db:seed
```

Sekian, Gomawo^-^
