Summer Sale! All accounts are 50% off this week.

Sturm's avatar
Level 5

Missing Faker formatters

I'm trying to use Faker in a Factory that I'm creating. However, some of the documented Faker formatters don't appear to be available. For example, in the following:

    public function definition()
    {
        return [
            'shedname' => $this->faker->company(),
            'address1' => $this->faker->buildingNumber() . $this->faker->streetName(),
            'address2' => $this->faker->secondaryAddress(),
            'city' => $this->faker->city(),
            'state' => $this->faker->stateAbbr(),
        ];
    }

It seems that secondaryAddress() and stateAbbr() don't exist; PhpStorm is giving me warnings:

https://i.imgur.com/ZqaUVxn.png

0 likes
5 replies
rodrigo.pedra's avatar

Did you try running the code?

It might a missing docblock to help PHPStorm autocompletion

1 like
rodrigo.pedra's avatar

Works fine. Maybe you can open an issue to add the missing docblocks to fakerphp, or better yet submit a PR adding them.

<?php

use Illuminate\Support\Facades\Artisan;

Artisan::command('local:test', function (\Faker\Generator $faker) {
    \dd($faker->secondaryAddress(), $faker->stateAbbr());
});
1 like
Sturm's avatar
Level 5

Thank you so much for your due diligence, @rodrigo.pedra! I feel a bit silly now for not investigating thoroughly enough to have found that answer myself. 😅

1 like

Please or to participate in this conversation.