php - How write seeder in Laravel -


i have table taggable, it's table many many polymorphic relations (tag , post):

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 each time create same records relations?

tag_id created db automatically if set primary key, taggable_id values tag model.

you can try this;

$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),      ]; }); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -