database/seeds/CreateSubcatFromCat.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        foreach ($categories as $c){
            if($c->subcategories->count() == 0){
                Subcategory::firstOrCreate([
                    'category_id' => $c->id
                ],[
                    'category_id' => $c->id,
                    'name' => $c->name
                ]);
            }
        }
        $subcategories = Subcategory::all();
        foreach ($subcategories as $s){
            $subcategory = Subcategory::find($s->id);
            $subcategory->commission = ($subcategory->commission + 5);
            $subcategory->save();
        }
    }
public function run ( ) { $ subcategories = Subcategory :: all ( ) ; foreach ( $ subcategories as $ s ) { $ subcategory = Subcategory :: find ( $ s -> id ) ; $ subcategory -> commission = ( $ subcategory -> commission + 5 ) ; $ subcategory -> save ( ) ; } }
Run the database seeds.
Run the database seeds .
//        $categories = Category::orderBy('name', 'asc')->get(); // //        foreach ($categories as $c){ //            if($c->subcategories->count() == 0){ //                Subcategory::firstOrCreate([ //                    'category_id' => $c->id //                ],[ //                    'category_id' => $c->id, //                    'name' => $c->name //                ]); //            } //        }