This repository has been archived on 2025-12-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

61 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2025-10-20 08:57:51 +02:00
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContactFactory extends Factory
{
protected $model = \App\Models\Contact::class;
public function definition()
{
// 30% chance of having an avatar, 70% chance of having null
$hasAvatar = $this->faker->boolean(30);
$avatar = null;
if ($hasAvatar) {
// Generate a random image ID between 1 and 70 (pravatar.cc has 70 default images)
$randomImageId = $this->faker->numberBetween(1, 70);
$avatar = "https://i.pravatar.cc/128?img={$randomImageId}";
}
2025-10-29 13:53:08 +01:00
$gender = rand(0, 9) >= 5 ? 'female' : 'male';
$userName = $this->faker->userName();
$hasLinkedIn = rand(0, 9) >= 7;
$hasMatrix = rand(0, 9) >= 7;
$hasGithub = rand(0, 9) >= 7;
$contact = [
'is_primary' => $this->faker->boolean(30),
2025-10-29 13:53:08 +01:00
'salutation' => $this->faker->title($gender),
'first_name' => $this->faker->firstName($gender),
'last_name' => $this->faker->lastName($gender),
'job_title' => $this->faker->jobTitle(),
2025-10-20 08:57:51 +02:00
'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->phoneNumber(),
'mobile_phone' => $this->faker->phoneNumber(),
2025-10-20 08:57:51 +02:00
'avatar' => $avatar,
'online_accounts' => []
];
if ($hasLinkedIn) $contact[] = [
'platform' => 'linkedin',
'user_name' => $userName,
'url' => 'https://www.linkedin.com/in/' . $userName
];
if ($hasMatrix) $contact[] = [
'platform' => 'matrix',
'user_name' => $userName,
'url' => '@' . $userName . ':matrix.org'
2025-10-20 08:57:51 +02:00
];
if ($hasGithub) $contact[] = [
'platform' => 'github',
'user_name' => $userName,
'url' => 'https://www.github.com/' . $userName
];
return $contact;
2025-10-20 08:57:51 +02:00
}
}