mercredi 24 janvier 2018

Is it possible to extract the individual components of a fzaninotto Faker formatter?

Is it possible to access and extract the components of a faker provider like Address. For instance, I need only the stateAbbr to populate one column in my database, not the whole address.

I tried something like $faker->address->stateAbbr but of course it throws an error

//This is thehttps://stackoverflow.com/questions/17418750/is-it-possible-to-extract-the-value-from-processing-instruction-define-with provider

Faker\Provider\en_US\Address
cityPrefix                          // 'Lake'
secondaryAddress                    // 'Suite 961'
state                               // 'NewMexico'
stateAbbr                           // 'OH'
citySuffix                          // 'borough'
streetSuffix                        // 'Keys'
buildingNumber                      // '484'
city                                // 'West Judge'
streetName                          // 'Keegan Trail'
streetAddress                       // '439 Karley Loaf Suite 897'
postcode                            // '17916'
address                             // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
country                             // 'Falkland Islands (Malvinas)'
latitude($min = -90, $max = 90)     // 77.147489
longitude($min = -180, $max = 180)  // 86.211205 

//This is my code

use Faker\Generator as Faker;    
$factory->define(App\Company::class, function (Faker $faker) {
    return [
        'city'=>$faker->city,
        'state'=>$faker->address->stateAbbr,//Getiing an error here
    ];

});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire