首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mobileNumber控制器中未知格式的Laravel

mobileNumber控制器中未知格式的Laravel
EN

Stack Overflow用户
提问于 2021-12-09 10:28:01
回答 1查看 820关注 0票数 0

我在Laravel项目中使用PHP,我需要在种子文件中使用Faker,而不是工厂文件,我从一个工厂文件中迁移它,然后抛出一个错误:

未知格式"mobileNumber“

这在工厂里很好,但为什么我的播种机文件不行呢?

我遗漏了什么?

代码语言:javascript
复制
<?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);
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-12-09 10:50:01

你可以用phoneNumber代替,例如$faker->phoneNumber;

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70288260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档