42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories\Blog;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use App\Models\Blog\Post;
|
|
use App\Models\Blog\Category;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Tag>
|
|
*/
|
|
class PostFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
|
|
protected $model = Post::class;
|
|
|
|
|
|
public function definition(): array
|
|
{
|
|
$title = $this->faker->sentence;
|
|
return [
|
|
'title' => $title,
|
|
'body' => $this->faker->paragraphs(5, true),
|
|
'excerpt' => $this->faker->text(200),
|
|
'slug' => Str::slug($title) . '-' . $this->faker->unique()->numberBetween(1, 1000),
|
|
'author_id' => User::inRandomOrder()->first()->id ?? User::factory(),
|
|
'category_id' => Category::inRandomOrder()->first()->id ?? Category::factory(),
|
|
'featured_image' => $this->faker->imageUrl(800, 600, 'technics', true),
|
|
'views' => $this->faker->numberBetween(0, 1000),
|
|
'likes' => $this->faker->numberBetween(0, 500),
|
|
'published_at' => $this->faker->dateTimeBetween('-1 years', 'now'),
|
|
];
|
|
}
|
|
}
|