Add initial Code
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?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}";
|
||||
}
|
||||
|
||||
return [
|
||||
'first_name' => $this->faker->firstName(),
|
||||
'last_name' => $this->faker->lastName(),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'position' => $this->faker->jobTitle(),
|
||||
'is_primary' => $this->faker->boolean(30),
|
||||
'avatar' => $avatar,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user