database/seeds/PostSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        factory(Post::class, 20) -> make() -> each(function($post, $cat) {
            $user = User::inRandomOrder() -> limit(1) -> first();
            $cat = Cat::inRandomOrder() -> limit(1) -> first();
            $post -> user() -> associate($user);
            $post -> cat() -> associate($cat);
            $post -> save();
        });
    }
public function run ( ) { factory ( Post :: class , 20 ) -> make ( ) -> each ( function ( $ post , $ cat ) { $ user = User :: inRandomOrder ( ) -> limit ( 1 ) -> first ( ) ; $ cat = Cat :: inRandomOrder ( ) -> limit ( 1 ) -> first ( ) ; $ post -> user ( ) -> associate ( $ user ) ; $ post -> cat ( ) -> associate ( $ cat ) ; $ post -> save ( ) ; } ) ; }
Run the database seeds.
Run the database seeds .