ldc-crm/database/factories/CustomerInfoFactory.php
2025-07-28 09:07:54 +02:00

52 lines
1.6 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\Country;
use App\Models\CustomerInfo;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
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(): array
{
$faker = \Faker\Factory::create('fr_FR');
$faker->addProvider(new \Faker\Provider\fr_FR\Address($faker));
$faker->addProvider(new \Faker\Provider\fr_FR\PhoneNumber($faker));
$countries = Country::toArray();
$country = $countries[\array_rand($countries)];
$phone = $faker->phoneNumber;
try {
Validator::validate(['phone' => $phone], ['phone' => 'string|phone:FR,BE,LU']);
} catch (ValidationException $e) {
$phone = '0388982532';
}
return [
'firstname' => $faker->firstName,
'lastname' => $faker->lastName,
'birth_date' => $faker->dateTimeBetween('-60 years', '-18 years'),
'address' => $faker->address,
'address2' => '',
'phone' => $phone,
'country' => $country->value,
'city' => $faker->city,
'postcode' => $faker->postcode,
'opt_in' => $faker->boolean,
'hashcode' => $faker->sha1
];
}
}