laravel-learn-bbs/database/factories/TopicFactory.php

22 lines
610 B
PHP
Raw Normal View History

2018-01-01 04:00:45 +00:00
<?php
use Faker\Generator as Faker;
$factory->define(App\Models\Topic::class, function (Faker $faker) {
2018-01-01 04:38:52 +00:00
//随机生成『小段落』文本
$sentence = $faker->sentence();
// 随机取一个月以内的时间
$updated_at = $faker->dateTimeThisMonth();
// 传参为生成最大时间不超过,创建时间永远比更改时间要早
$created_at = $faker->dateTimeThisMonth($updated_at);
2018-01-01 04:00:45 +00:00
return [
2018-01-01 04:38:52 +00:00
'title' => $sentence,
'body' => $faker->text(),
'excerpt' => $sentence,
'created_at' => $created_at,
'updated_at' => $updated_at,
2018-01-01 04:00:45 +00:00
];
});