41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use App\Models\{Article, ArticleCategory};
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Article>
|
|
*/
|
|
class ArticleFactory extends Factory
|
|
{
|
|
protected $model = Article::class;
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition()
|
|
{
|
|
$imgs = [
|
|
'https://qiniu.abcdefg.fun/banner.png',
|
|
'https://qiniu.abcdefg.fun/banner1.png',
|
|
'https://qiniu.abcdefg.fun/banner2.png',
|
|
'https://qiniu.abcdefg.fun/banner3.png',
|
|
];
|
|
$category = ArticleCategory::where('level', 3)->inRandomOrder()->first();
|
|
return [
|
|
'author' => $this->faker->name(),
|
|
'category_id' => $category->id,
|
|
'category_path' => $category->path . $category->id . '-',
|
|
'content' => $this->faker->text(),
|
|
'cover' => $this->faker->randomElement($imgs),
|
|
'published_at' => now(),
|
|
'sort' => 0,
|
|
'sub_title' => $this->faker->sentence,
|
|
'title' => $this->faker->sentence,
|
|
];
|
|
}
|
|
}
|