database/seeds/PostTagSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {   
        $posts = Post::all();
        foreach ($posts as $post) {
            $randomNum = random_int(1,4);
            $tags = Tag::inRandomOrder()->limit($randomNum)->get();
            $post->tags()->attach($tags);
        }
    }
public function run ( ) { $ posts = Post :: all ( ) ; foreach ( $ posts as $ post ) { $ randomNum = random_int ( 1 , 4 ) ; $ tags = Tag :: inRandomOrder ( ) -> limit ( $ randomNum ) -> get ( ) ; $ post -> tags ( ) -> attach ( $ tags ) ; } }
Run the database seeds.
Run the database seeds .
// $tags = Tag::all();