feat: Add CompanySeeder to populate partner media and journalists, and refactor company verification status to an enum.
This commit is contained in:
parent
ee39b1f33a
commit
87b0275151
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\VerificationStatus;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
@ -34,8 +35,8 @@ public function definition(): array
|
||||
'annual_tax_return' => $this->faker->numerify('SPT-####-########'),
|
||||
'domicile_certificate' => $this->faker->numerify('###/###/DOMISILI/####'),
|
||||
'profile' => $this->faker->numerify('PROFILE-####-########'),
|
||||
'validated_at' => $this->faker->optional(0.7)->dateTimeBetween('-1 year', 'now'),
|
||||
'rejection_reason' => $this->faker->optional(0.1)->sentence(),
|
||||
'profile' => $this->faker->numerify('PROFILE-####-########'),
|
||||
'status' => VerificationStatus::PENDING,
|
||||
];
|
||||
}
|
||||
|
||||
@ -45,8 +46,7 @@ public function definition(): array
|
||||
public function validated(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'validated_at' => $this->faker->dateTimeBetween('-6 months', 'now'),
|
||||
'rejection_reason' => null,
|
||||
'status' => VerificationStatus::APPROVED,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -56,8 +56,7 @@ public function validated(): static
|
||||
public function rejected(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'validated_at' => null,
|
||||
'rejection_reason' => $this->faker->sentence(),
|
||||
'status' => VerificationStatus::REJECTED,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -67,8 +66,7 @@ public function rejected(): static
|
||||
public function pending(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'validated_at' => null,
|
||||
'rejection_reason' => null,
|
||||
'status' => VerificationStatus::PENDING,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public function definition(): array
|
||||
'company_id' => Company::factory(),
|
||||
'name' => $this->faker->randomElement($mediaNames),
|
||||
'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,
|
||||
'classification' => $this->faker->randomElement(MediaClassification::cases())->value,
|
||||
'journalism_organization' => $this->faker->optional(0.6)->randomElement([
|
||||
@ -63,7 +63,7 @@ public function online(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => MediaType::ONLINE->value,
|
||||
'link' => $this->faker->url(),
|
||||
'link' => $this->faker->domainName(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ public function definition(): array
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'username' => $this->faker->unique()->userName(),
|
||||
'username' => $this->faker->unique()->bothify('?????#####'),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
|
||||
30
database/seeders/CompanySeeder.php
Normal file
30
database/seeders/CompanySeeder.php
Normal 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]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ public function run(): void
|
||||
$this->call([
|
||||
ShieldSeeder::class,
|
||||
UserSeeder::class,
|
||||
CompanySeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user