database/seeders/DatabaseSeeder.php
/**
     * Seed the application's database.
     *
     * @return void
     */
Seed the application's database.
@return void
Seed the application ' s database . @return void
public function run()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
        User::truncate();
        Product::truncate();
        Category::truncate();
        Transaction::truncate();
        DB::table('category_product')->truncate();
        User::flushEventListeners();
        Product::flushEventListeners();
        Category::flushEventListeners();
        Transaction::flushEventListeners();
        $this->call(RoleSeeder::class);
        User::factory(100)->create();
        User::factory(100)->create();
        $productos = Product::factory(300)->create();
        Transaction::factory(200)->create();
        Category::factory(30)->create();
        foreach($productos as $producto){
            $producto->categories()->attach(
                rand(1,5)
            );
        }        
    }
public function run ( ) { DB :: statement ( 'SET FOREIGN_KEY_CHECKS = 0' ) ; User :: truncate ( ) ; Product :: truncate ( ) ; Category :: truncate ( ) ; Transaction :: truncate ( ) ; DB :: table ( 'category_product' ) -> truncate ( ) ; User :: flushEventListeners ( ) ; Product :: flushEventListeners ( ) ; Category :: flushEventListeners ( ) ; Transaction :: flushEventListeners ( ) ; $ this -> call ( RoleSeeder :: class ) ; User :: factory ( 100 ) -> create ( ) ; User :: factory ( 100 ) -> create ( ) ; $ productos = Product :: factory ( 300 ) -> create ( ) ; Transaction :: factory ( 200 ) -> create ( ) ; Category :: factory ( 30 ) -> create ( ) ; foreach ( $ productos as $ producto ) { $ producto -> categories ( ) -> attach ( rand ( 1 , 5 ) ) ; } }
Seed the application's database.
Seed the application ' s database .