/databases/factories/ModelFactory.php 定义article的factory 出现问题

$factory->define(App\Article::class,function (Faker\Generator $faker){
    return [
        'title' => $faker->name,
        'content' => $faker->text,
        'published_at'=>\Carbon\Carbon::now(),
        'intro'=>$faker->text,
        'user_id'=>str_random(10)
    ];
});<br></br>

在tinker 指令下出现 InvalidArgumentException with message 'Trailing data' 错误,据查是 published_at 出现错误,请问时间字段怎么设置假数据呢?

JellyBool

确定是 published_at 么?你的 user_id 有考虑过?全部的错误信息是怎么样的?如果是 published_at ,你试试在 Article 添加:

protected $dates = ['published_at'];
ciotas

@JellyBool
我默认user_id为1 ,并注释了这段代码就可以了

public function setPublishedAtAttribute($date){
        $this->attributes['published_at']=Carbon::createFromFormat('Y-m-d',$date);
}

请问是什么原因呢,user_id为外键,如果取users表的id值,且随机,该怎样修改呢?

JellyBool

我记得这个user_id为外键,如果取users表的id值,且随机在社区的系列就有说到吧

https://laravist.com/series/develop-a-forum-using-laravel-5/episodes/2

HectorChan

@JellyBool 为什么你的视频下面没有品论,然后找看你个人主页才找到这里可以评论的?

JellyBool

视频的评论后面是用的 disqus,最近好像被墙了吧 @HectorChan

HectorChan

@JellyBool 没有理由啊,我可以看见别人的留言,但是没有看见有发表评论这个Button

JellyBool

那是之前的吧,后面就不开设评论的功能了 @HectorChan