28 lines
669 B
PHP
28 lines
669 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
use App\Models\Guest;
|
|
|
|
class GuestFactory extends Factory
|
|
{
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'id_pelanggan' => null, // Diisi oleh seeder
|
|
'nama_tamu' => $this->faker->name(),
|
|
'kode_invitasi' => $this->generateUniqueInvitationCode(),
|
|
];
|
|
}
|
|
|
|
protected function generateUniqueInvitationCode(): string
|
|
{
|
|
do {
|
|
$code = 'INV-' . strtoupper(Str::random(6));
|
|
} while (Guest::where('kode_invitasi', $code)->exists());
|
|
|
|
return $code;
|
|
}
|
|
} |