我有表可加標籤寫播種機,它的表多對多多態關係(標籤和後):如何在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) –