truncate(); DB::table('ranges')->truncate(); Schema::enableForeignKeyConstraints(); File::deleteDirectory(\storage_path('app/public/modelfiles/ranges')); File::deleteDirectory(\storage_path('app/public/modelfiles/products')); $this->call(RangeSeeder::class); Range::all()->each(function (Range $range) { Product::factory(6)->make()->each(function (Product $product) use ($range) { $product->picture = FileStorageHelper::storeFile( new Range(), new \SplFileInfo( \resource_path('../database/factories/assets/products/default-picture-550x550.jpg') ) ); $product->range()->associate($range); $product->saveQuietly(); }); }); } }