47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Publication;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<Publication>
|
|
*/
|
|
class PublicationFactory extends Factory
|
|
{
|
|
public function definition(): array
|
|
{
|
|
$status = $this->faker->randomElement(['draft', 'published', 'scheduled']);
|
|
|
|
return [
|
|
'post_id' => \App\Models\Post::factory(),
|
|
'channel_id' => \App\Models\Channel::factory(),
|
|
'title' => $this->faker->sentence(6),
|
|
'excerpt' => $this->faker->sentences(2, true),
|
|
'slug' => $this->faker->unique()->slug(),
|
|
'status' => $status,
|
|
'published_at' => $status === 'draft' ? null : $this->faker->dateTimeBetween('-1 year', 'now'),
|
|
'meta_title' => $this->faker->sentence(5),
|
|
'meta_description' => $this->faker->sentences(2, true),
|
|
'og_image' => null,
|
|
'canonical_url' => null,
|
|
];
|
|
}
|
|
|
|
public function published(): static
|
|
{
|
|
return $this->state([
|
|
'status' => 'published',
|
|
'published_at' => $this->faker->dateTimeBetween('-6 months', 'now'),
|
|
]);
|
|
}
|
|
|
|
public function draft(): static
|
|
{
|
|
return $this->state([
|
|
'status' => 'draft',
|
|
'published_at' => null,
|
|
]);
|
|
}
|
|
}
|