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
Caramel-CRM-Backup/database/factories/ContactFactory.php
T

37 lines
1.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';
return [
'salutation' => $this->faker->title($gender),
'first_name' => $this->faker->firstName($gender),
'last_name' => $this->faker->lastName($gender),
'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->phoneNumber(),
'position' => $this->faker->jobTitle(),
'is_primary' => $this->faker->boolean(30),
'avatar' => $avatar,
];
}
}