database/seeds/CategoriesTableSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        foreach(range(1,5) as $c)
        {
            $category=Category::create(['category' => "Category {$c}"]);
            $products = [];
            foreach(range(1, rand(1,5)) as $s){
                $products[]=['product'=>  "Product{$c} {$s}"];
            }
                $category->products()->createMany($products);
        }
    }
public function run ( ) { foreach ( range ( 1 , 5 ) as $ c ) { $ category = Category :: create ( [ 'category' => " Category  { $ c } " ] ) ; $ products = [ ] ; foreach ( range ( 1 , rand ( 1 , 5 ) ) as $ s ) { $ products [ ] = [ 'product' => " Product { $ c } { $ s } " ] ; } $ category -> products ( ) -> createMany ( $ products ) ; } }
Run the database seeds.
Run the database seeds .