我有表可加标签写播种机,它的表多对多多态关系(标签和后):如何在Laravel
taggable_id - id of Post
tag_id - id of Tag
taggable type - location of post model (default value"App/Models/Posts/Post")
is_search_term - boolen (0 or 1)
如何创建,每个时间关系创建相同记录的播种机?
我有表可加标签写播种机,它的表多对多多态关系(标签和后):如何在Laravel
taggable_id - id of Post
tag_id - id of Tag
taggable type - location of post model (default value"App/Models/Posts/Post")
is_search_term - boolen (0 or 1)
如何创建,每个时间关系创建相同记录的播种机?
如果Tag_id设置为主键,tag_id将由db自动创建,taggable_id可以从Tag模型获取值。
你可以尝试这样的事情;
$factory->define(App\Tag::class, function (Faker\Generator $faker) {
return [
'taggable_id' => random_int(\DB::table('posts')->min('id'), \DB::table('posts')->max('id')),
'is_search_term'=>$faker->numberBetween(0,1),
'taggable_type'=>$faker->sentence(2),
];
});
这可能有助于尽管它laravel4 [Laravel 4:用种子关系工作(https://stackoverflow.com/questions/14666277/laravel-4-working-with-relationships-in-seeds) –