2017-08-15 71 views
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) 

如何創建播種機這對於後期ID爲1(taggable_id)設爲0標籤ID。

對於交ID爲2組標籤id 1.

對於交ID爲3組標籤id 1和id 2.

回答

1

嘗試此。檢查模型的名稱空間是否符合慣例。由於您的'taggable type'屬性具有默認類型,因此將其從通過faker進行種子排除。

$factory->define(App/Models/Posts/Post::class, function (Faker\Generator $faker) { 

return [ 
    'taggable_id' => function(){ 
     return factory('App/Models/Posts/Post')->create()->id; 
    }, 
    'tag_id' => function(){ 
     return factory('App/Models/Tags/Tag')->create()->id; 
    }, 
    'is_search_term' => $faker->boolean 
]; }); 
+0

它工作這樣post_id = tag_id – Georg

+0

@Georg你能否詳細說明隊友? – sndsabin

+0

我想該算法創建的字段是這樣的: – Georg