feat: Add CompanySeeder to populate partner media and journalists, and refactor company verification status to an enum.

This commit is contained in:
Yoga Pangestu 2026-01-19 09:13:02 +07:00
parent ee39b1f33a
commit 87b0275151
5 changed files with 40 additions and 11 deletions

View File

@ -2,6 +2,7 @@
namespace Database\Factories; namespace Database\Factories;
use App\Enums\VerificationStatus;
use App\Models\Company; use App\Models\Company;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
@ -34,8 +35,8 @@ public function definition(): array
'annual_tax_return' => $this->faker->numerify('SPT-####-########'), 'annual_tax_return' => $this->faker->numerify('SPT-####-########'),
'domicile_certificate' => $this->faker->numerify('###/###/DOMISILI/####'), 'domicile_certificate' => $this->faker->numerify('###/###/DOMISILI/####'),
'profile' => $this->faker->numerify('PROFILE-####-########'), 'profile' => $this->faker->numerify('PROFILE-####-########'),
'validated_at' => $this->faker->optional(0.7)->dateTimeBetween('-1 year', 'now'), 'profile' => $this->faker->numerify('PROFILE-####-########'),
'rejection_reason' => $this->faker->optional(0.1)->sentence(), 'status' => VerificationStatus::PENDING,
]; ];
} }
@ -45,8 +46,7 @@ public function definition(): array
public function validated(): static public function validated(): static
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [
'validated_at' => $this->faker->dateTimeBetween('-6 months', 'now'), 'status' => VerificationStatus::APPROVED,
'rejection_reason' => null,
]); ]);
} }
@ -56,8 +56,7 @@ public function validated(): static
public function rejected(): static public function rejected(): static
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [
'validated_at' => null, 'status' => VerificationStatus::REJECTED,
'rejection_reason' => $this->faker->sentence(),
]); ]);
} }
@ -67,8 +66,7 @@ public function rejected(): static
public function pending(): static public function pending(): static
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [
'validated_at' => null, 'status' => VerificationStatus::PENDING,
'rejection_reason' => null,
]); ]);
} }
} }

View File

@ -43,7 +43,7 @@ public function definition(): array
'company_id' => Company::factory(), 'company_id' => Company::factory(),
'name' => $this->faker->randomElement($mediaNames), 'name' => $this->faker->randomElement($mediaNames),
'address' => $this->faker->address(), 'address' => $this->faker->address(),
'link' => $this->faker->optional(0.8)->url(), 'link' => $this->faker->optional(0.8)->domainName(),
'type' => $this->faker->randomElement(MediaType::cases())->value, 'type' => $this->faker->randomElement(MediaType::cases())->value,
'classification' => $this->faker->randomElement(MediaClassification::cases())->value, 'classification' => $this->faker->randomElement(MediaClassification::cases())->value,
'journalism_organization' => $this->faker->optional(0.6)->randomElement([ 'journalism_organization' => $this->faker->optional(0.6)->randomElement([
@ -63,7 +63,7 @@ public function online(): static
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [
'type' => MediaType::ONLINE->value, 'type' => MediaType::ONLINE->value,
'link' => $this->faker->url(), 'link' => $this->faker->domainName(),
]); ]);
} }

View File

@ -26,7 +26,7 @@ public function definition(): array
return [ return [
'name' => fake()->name(), 'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(), 'email' => fake()->unique()->safeEmail(),
'username' => $this->faker->unique()->userName(), 'username' => $this->faker->unique()->bothify('?????#####'),
'email_verified_at' => now(), 'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'), 'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10), 'remember_token' => Str::random(10),

View File

@ -0,0 +1,30 @@
<?php
namespace Database\Seeders;
use App\Enums\RoleEnum;
use App\Models\Journalist;
use App\Models\PartnerMedia;
use Illuminate\Database\Seeder;
class CompanySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
PartnerMedia::factory()
->count(3)
->create()
->each(function ($media) {
// Assign role to the user associated with the company
$media->company->user->assignRole(RoleEnum::PERUSAHAAN);
// Create journalists for the media
Journalist::factory()
->count(random_int(1, 3))
->create(['partner_media_id' => $media->id]);
});
}
}

View File

@ -17,6 +17,7 @@ public function run(): void
$this->call([ $this->call([
ShieldSeeder::class, ShieldSeeder::class,
UserSeeder::class, UserSeeder::class,
CompanySeeder::class,
]); ]);
} }
} }