36 lines
991 B
PHP
36 lines
991 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
|
||
|
|
*/
|
||
|
|
class PostFactory extends Factory
|
||
|
|
{
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
$title = rtrim(fake()->sentence(rand(4, 8)), '.');
|
||
|
|
|
||
|
|
return [
|
||
|
|
'title' => $title,
|
||
|
|
'slug' => Str::slug($title) . '-' . fake()->unique()->numberBetween(1, 100000),
|
||
|
|
'excerpt' => fake()->sentence(rand(15, 25)),
|
||
|
|
'body' => implode("\n\n", fake()->paragraphs(rand(4, 7))),
|
||
|
|
'cover_image' => null,
|
||
|
|
'author_id' => User::query()->inRandomOrder()->value('id'),
|
||
|
|
'published_at' => now()->subDays(fake()->numberBetween(0, 60)),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function draft(): static
|
||
|
|
{
|
||
|
|
return $this->state(fn (array $attributes) => [
|
||
|
|
'published_at' => null,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|