Files

66 lines
2.1 KiB
PHP

<?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}";
}
$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;
$onlineAccounts = [];
if ($hasLinkedIn) {
$onlineAccounts[] = [
'platform' => 'linkedin',
'user_name' => $userName,
'url' => 'https://www.linkedin.com/in/' . $userName
];
}
if ($hasMatrix) {
$onlineAccounts[] = [
'platform' => 'matrix',
'user_name' => $userName,
'url' => '@' . $userName . ':matrix.org'
];
}
if ($hasGithub) {
$onlineAccounts[] = [
'platform' => 'github',
'user_name' => $userName,
'url' => 'https://www.github.com/' . $userName
];
}
return [
'is_primary' => $this->faker->boolean(30),
'salutation' => $this->faker->title($gender),
'first_name' => $this->faker->firstName($gender),
'last_name' => $this->faker->lastName($gender),
'job_title' => $this->faker->jobTitle(),
'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->phoneNumber(),
'mobile_phone' => $this->faker->phoneNumber(),
'avatar' => $avatar,
'online_accounts' => $onlineAccounts
];
}
}