我在Laravel项目中使用PHP,我需要在种子文件中使用Faker,而不是工厂文件,我从一个工厂文件中迁移它,然后抛出一个错误:
未知格式"mobileNumber“
这在工厂里很好,但为什么我的播种机文件不行呢?
我遗漏了什么?
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Application;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Hashids\Hashids;
use Faker\Factory as Faker;
class ApplicationsSeeder extends Seeder
{
private $applicants = [];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
for ($i = 0; $i < 51; $i++) {
$hashids = new Hashids('', 7);
$bank = $faker->bankAccountNumber('', '', 8);
$sort = rand(111111, 999999);
$hashable = $bank . '' . $sort;
$hashable = trim($hashable);
// email formatting
$email = $faker->safeEmail ?? null;
$email = trim(str_replace(' ', '', $email));
// postcode formatting
$postcode = $faker->postcode ?? null;
$postcode = trim(strtoupper(str_replace(' ', '', $postcode)));
// mobile formatting
$mobile = $faker->mobileNumber ?? null;
$mobile = trim(str_replace(' ', '', $mobile));
$application = [
'ApiKey' => Str::random(35),
'AffId' => "aff2020",
'Application' => [
'AppFirstName' => $faker->firstName,
'AppLastName' => $faker->lastName,
'AppEmail' => $email,
'BankSortcode' => $sort,
'BankAccount' => $bank,
'AppMobilePhone' => $mobile
]
];
$applicants[] = [
'hash' => $hashids->encode($hashable),
'product_type' => 'payday_form_honeycomb_faker',
'email' => $email,
'birthday' => Carbon::now()->subYears(rand(20, 50))->subMonths(1, 12)->subDays(1, 25)->toDateString(),
'postcode' => $postcode,
'mobile' => $mobile,
'data' => json_encode($application),
'verified_at' => Carbon::now(),
'created_at' => Carbon::now()->toDateTimeString(),
'updated_at' => Carbon::now()->toDateTimeString()
];
}
foreach ($applicants as $applicant) {
Applicant::insert($applicant);
}
}
}发布于 2021-12-09 10:50:01
你可以用phoneNumber代替,例如$faker->phoneNumber;
https://stackoverflow.com/questions/70288260
复制相似问题