47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Enums\PostStatus;
|
||
|
|
use App\Models\Category;
|
||
|
|
use App\Models\Post;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends Factory<Post>
|
||
|
|
*/
|
||
|
|
class PostFactory extends Factory
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
$title = fake()->unique()->sentence();
|
||
|
|
$publishedAt = fake()->dateTimeBetween('-6 months', 'now');
|
||
|
|
|
||
|
|
return [
|
||
|
|
'user_id' => User::factory(),
|
||
|
|
'category_id' => Category::factory(),
|
||
|
|
'title' => rtrim($title, '.'),
|
||
|
|
'slug' => Str::slug($title),
|
||
|
|
'excerpt' => fake()->sentence(20),
|
||
|
|
'body' => implode("\n\n", fake()->paragraphs(6)),
|
||
|
|
'status' => PostStatus::Published,
|
||
|
|
'published_at' => $publishedAt,
|
||
|
|
'meta_title' => null,
|
||
|
|
'meta_description' => null,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function draft(): static
|
||
|
|
{
|
||
|
|
return $this->state(fn () => [
|
||
|
|
'status' => PostStatus::Draft,
|
||
|
|
'published_at' => null,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|