php - Seeder for pivot table -


i have pivot table taggable, it's table many many polymorphic relations (tag , post) in 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) 

how create seeder post id 1 (taggable_id) set 0 tag id.

for post id 2 set tag id 1.

for post id 3 set tag id 1 , id 2.

try this. check namespace of model if matches convention or not .since 'taggable type' attribute has default type, excluded seeding through 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 ]; }); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -