getTable())->truncate(); Schema::enableForeignKeyConstraints(); File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Range())->getTable())); $fonts = Font::all(); Brand::all()->each( fn(Brand $brand) => Range::factory(\random_int(6, 16))->make()->each(function (Range $range) use ($brand, $fonts) { if ($range->width === 1) { $range->picture = FileHelper::storeFile( new Range(), new \SplFileInfo( \resource_path('../database/factories/assets/ranges/default-picture-600x500.jpg') ), prefix: $range->tenant_id ); } else { $range->picture = FileHelper::storeFile( new Range(), new \SplFileInfo( \resource_path('../database/factories/assets/ranges/default-picture-1300x500.jpg') ), prefix: $range->tenant_id ); } $range->brand()->associate($brand); $range->font()->associate($fonts->random(1)->first()); $range->save(); }) ); } }