simedkom/database/factories/ContentRecapFactory.php
2026-01-29 11:20:23 +07:00

111 lines
2.8 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\ContentType;
use App\Enums\SocialMedia;
use App\Models\Classification;
use App\Models\ContentRecap;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ContentRecap>
*/
class ContentRecapFactory extends Factory
{
protected $model = ContentRecap::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$channels = [
'Website',
'Facebook',
'Instagram',
'Twitter',
'YouTube',
'TikTok',
'WhatsApp',
'Telegram',
'LinkedIn',
];
return [
'classification_id' => Classification::factory(),
'title' => $this->faker->sentence(4),
'link' => $this->faker->optional(0.8)->url(),
'posting_date' => $this->faker->dateTimeBetween('-6 months', 'now')->format('Y-m-d'),
'type' => $this->faker->randomElement(ContentType::cases())->value,
'channel' => $this->faker->randomElement($channels),
'social_media' => $this->faker->randomElement(SocialMedia::cases())->value,
];
}
/**
* Indicate that the content recap is photo type.
*/
public function photo(): static
{
return $this->state(fn (array $attributes) => [
'type' => ContentType::FOTO->value,
]);
}
/**
* Indicate that the content recap is video type.
*/
public function video(): static
{
return $this->state(fn (array $attributes) => [
'type' => ContentType::VIDEO->value,
'channel' => $this->faker->randomElement(['YouTube', 'Instagram', 'TikTok']),
]);
}
/**
* Indicate that the content recap is text type.
*/
public function text(): static
{
return $this->state(fn (array $attributes) => [
'type' => ContentType::TEXT->value,
]);
}
/**
* Indicate that the content recap is graphic type.
*/
public function graphic(): static
{
return $this->state(fn (array $attributes) => [
'type' => ContentType::GRAPHIC->value,
]);
}
/**
* Indicate that the content recap is for Instagram.
*/
public function instagram(): static
{
return $this->state(fn (array $attributes) => [
'channel' => 'Instagram',
'social_media' => 'Instagram',
]);
}
/**
* Indicate that the content recap is for Facebook.
*/
public function facebook(): static
{
return $this->state(fn (array $attributes) => [
'channel' => 'Facebook',
'social_media' => 'Facebook',
]);
}
}