Faker 得到 streetAddress 抛出 ErrorException
Faker get streetAddress throwing ErrorException
我正在构建一个 laravel 应用程序,我已经创建了一个 FakerServiceProvider 来填充用于测试和本地开发的工厂。
<?php
namespace App\Providers;
use Faker\Factory;
use Faker\Generator;
use Faker\Provider\en_GB\Address;
use Faker\Provider\en_GB\Person;
use Faker\Provider\en_GB\PhoneNumber;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
/**
* Class FakerServiceProvider
* @package App\Providers
*/
class FakerServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
*
*/
public function register()
{
$this->app->singleton(Generator::class, function ($app) {
$factory = Factory::create('en_GB');
$factory->addProvider(Person::class);
$factory->addProvider(Address::class);
$factory->addProvider(PhoneNumber::class);
return $factory;
});
}
/**
* @return array
*/
public function provides()
{
return [Generator::class];
}
}
我创建了一个地址工厂:
<?php
use App\Address;
use App\Country;
$factory->define(Address::class, function (Faker\Generator $faker) {
return [
'line_1' => $faker->secondaryAddress,
'line_2' => $faker->streetAddress,
'town' => $faker->city,
'county' => $faker->county,
'country_id' => factory(Country::class)->make()->id,
'postcode' => $faker->postcode,
'phone' => $faker->phoneNumber,
];
});
当我尝试使用该工厂时出现以下错误:
ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, non-static method Faker\Provider\Address::streetAddress() should not be called statically
我检查了 Faker 库的源代码,有一个 streetAddress 方法 here
我试过同时调用 $faker->streetAddress
和 $faker->streetAddress()with no luck. I would expect
$faker->streetAddressto produce something like
` 或类似的东西。
谁能帮我解释一下这个问题
删除 Faker Service Provider 中添加的提供程序修复了问题
我正在构建一个 laravel 应用程序,我已经创建了一个 FakerServiceProvider 来填充用于测试和本地开发的工厂。
<?php
namespace App\Providers;
use Faker\Factory;
use Faker\Generator;
use Faker\Provider\en_GB\Address;
use Faker\Provider\en_GB\Person;
use Faker\Provider\en_GB\PhoneNumber;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
/**
* Class FakerServiceProvider
* @package App\Providers
*/
class FakerServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
*
*/
public function register()
{
$this->app->singleton(Generator::class, function ($app) {
$factory = Factory::create('en_GB');
$factory->addProvider(Person::class);
$factory->addProvider(Address::class);
$factory->addProvider(PhoneNumber::class);
return $factory;
});
}
/**
* @return array
*/
public function provides()
{
return [Generator::class];
}
}
我创建了一个地址工厂:
<?php
use App\Address;
use App\Country;
$factory->define(Address::class, function (Faker\Generator $faker) {
return [
'line_1' => $faker->secondaryAddress,
'line_2' => $faker->streetAddress,
'town' => $faker->city,
'county' => $faker->county,
'country_id' => factory(Country::class)->make()->id,
'postcode' => $faker->postcode,
'phone' => $faker->phoneNumber,
];
});
当我尝试使用该工厂时出现以下错误:
ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, non-static method Faker\Provider\Address::streetAddress() should not be called statically
我检查了 Faker 库的源代码,有一个 streetAddress 方法 here
我试过同时调用 $faker->streetAddress
和 $faker->streetAddress()with no luck. I would expect
$faker->streetAddressto produce something like
` 或类似的东西。
谁能帮我解释一下这个问题
删除 Faker Service Provider 中添加的提供程序修复了问题