2021-03-14 10:45:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Country;
|
|
|
|
|
use App\Models\CustomerInfo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2021-12-19 15:57:24 +01:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Illuminate\Validation\ValidationException;
|
2021-03-14 10:45:42 +01:00
|
|
|
|
|
|
|
|
class CustomerInfoFactory extends Factory
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $model = CustomerInfo::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Define the model's default state.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function definition()
|
|
|
|
|
{
|
2021-12-19 15:57:24 +01:00
|
|
|
$faker = \Faker\Factory::create('fr_FR');
|
|
|
|
|
$faker->addProvider(new \Faker\Provider\fr_FR\Address($faker));
|
|
|
|
|
$faker->addProvider(new \Faker\Provider\fr_FR\PhoneNumber($faker));
|
2021-08-04 09:42:48 +02:00
|
|
|
$countries = Country::toArray();
|
2021-08-05 15:00:28 +02:00
|
|
|
$country = $countries[\array_rand($countries)];
|
2021-12-19 15:57:24 +01:00
|
|
|
$phone = $faker->phoneNumber;
|
|
|
|
|
try {
|
|
|
|
|
Validator::validate(['phone' => $phone], ['phone' => 'string|phone:FR,BE,LU']);
|
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
|
$phone = '0388982532';
|
|
|
|
|
}
|
2021-03-14 10:45:42 +01:00
|
|
|
return [
|
2021-12-19 15:57:24 +01:00
|
|
|
'firstname' => $faker->firstName,
|
|
|
|
|
'lastname' => $faker->lastName,
|
|
|
|
|
'birth_date' => $faker->dateTimeBetween('-60 years', '-18 years'),
|
|
|
|
|
'address' => $faker->address,
|
2021-03-14 10:45:42 +01:00
|
|
|
'address2' => '',
|
2021-12-19 15:57:24 +01:00
|
|
|
'phone' => $phone,
|
2023-09-04 13:08:34 +02:00
|
|
|
'country' => $country->value,
|
2021-12-19 15:57:24 +01:00
|
|
|
'city' => $faker->city,
|
|
|
|
|
'postcode' => $faker->postcode,
|
|
|
|
|
'opt_in' => $faker->boolean,
|
|
|
|
|
'hashcode' => $faker->sha1
|
2021-03-14 10:45:42 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|