/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $limit = 40; for ($i = 0; $i < $limit; $i++) { $tag = DB::table('tags')->insert(['value' => $faker->text($maxNbChars = 10)]); } $stories = App\Story::get(); foreach ($stories as $story) { $tag_id = rand(1, count(App\Tag::get())); DB::table('story_tag')->insert(['story_id' => $story->id, 'tag_id' => $tag_id]); } }
/** * Run the database seeds. * * @return void */ public function run() { // $faker = Faker\Factory::create(); $limit = 20; for ($i = 0; $i < $limit; $i++) { echo $faker->city; for ($i = 0; $i < $limit; $i++) { DB::table('tags')->insert(['value' => $faker->word]); } } $stories = App\Story::get(); foreach ($stories as $story) { $tag_id = $tag_id = rand(1, count(App\Tag::get())); DB::table('story_tag')->insert(['story_id' => $story->id, 'tag_id' => $tag_id]); } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $limit = 20; for ($i = 0; $i < $limit; $i++) { //DB::table('tags')->insert([ //'value' => $faker->word, //]); } $stories = App\Story::get(); foreach ($stories as $story) { //attach 3 random tags to each story $numbers = range(1, 20); shuffle($numbers); $story->tags()->attach($numbers[0]); $story->tags()->attach($numbers[1]); $story->tags()->attach($numbers[2]); } }
/** * Run the database seeds. * * @return void */ public function run() { /* //Run faker first and then add tags. $faker = Faker\Factory::create(); $limit = 20; for($i=0;$i<$limit;$i++) { DB::table('tags')->insert([//, 'value'=>$faker->word, ]); } */ $stories = App\Story::get(); foreach ($stories as $story) { $tag = rand(1, 20); $tag2 = rand(1, 20); $tag3 = rand(1, 20); $story->tags()->attach($tag); $story->tags()->attach($tag2); $story->tags()->attach($tag3); } }