*/ class VehicleFactory extends Factory { protected $model = Vehicle::class; /** * Configure the model factory. */ public function configure(): static { return $this->afterCreating(function (Vehicle $vehicle) { // Crear un Tag automáticamente después de crear el vehículo Tag::factory()->create([ 'vehicle_id' => $vehicle->id, 'folio' => $vehicle->folio, 'status' => 'assigned', ]); }); } /** * Define the model's default state. * * @return array */ public function definition(): array { $brands = [ 'CHEVROLET G.M.C.', 'NISSAN MEXICANA', 'VOLKSWAGEN', 'FORD MOTOR COMPANY', 'TOYOTA', 'HONDA', 'MAZDA', 'KIA MOTORS', 'HYUNDAI', ]; $types = ['SEDAN', 'SUV', 'PICKUP', 'HATCHBACK', 'VAN']; $colors = ['BLANCO', 'NEGRO', 'GRIS', 'ROJO', 'AZUL', 'PLATA']; $municipalities = ['CENTRO', 'CÁRDENAS', 'COMALCALCO', 'CUNDUACÁN', 'HUIMANGUILLO']; $year = fake()->numberBetween(2015, 2025); $vin = $this->generateVIN(); $placa = $this->generatePlaca(); return [ 'anio_placa' => (string) $year, 'placa' => $placa, 'numero_serie' => $vin, 'rfc' => 'GME' . fake()->numerify('######') . 'GJA', 'folio' => fake()->unique()->numerify('#######'), 'vigencia' => (string) ($year + 1), 'fecha_impresion' => fake()->date('d-m-Y'), 'qr_hash' => fake()->sha256(), 'valido' => fake()->boolean(95), // 95% válidos 'nombre' => strtoupper(fake()->company()), 'nombre2' => strtoupper(fake()->lexify('????*????')), 'municipio' => fake()->randomElement($municipalities), 'localidad' => 'VILLAHERMOSA', 'calle' => strtoupper(fake()->streetAddress()), 'calle2' => strtoupper(fake()->lexify('? ??*????')), 'tipo' => fake()->randomElement($types), 'tipo_servicio' => fake()->randomElement(['PARTICULAR', 'PUBLICO', 'OFICIAL']), 'marca' => fake()->randomElement($brands), 'linea' => strtoupper(fake()->word()), 'sublinea' => 'PAQ. "' . strtoupper(fake()->randomLetter()) . '" ' . strtoupper(fake()->word()), 'modelo' => $year, 'numero_motor' => strtoupper(fake()->bothify('??####??##')), 'descripcion_origen' => fake()->randomElement(['NACIONAL', 'IMPORTADO']), 'color' => fake()->randomElement($colors), 'codigo_postal' => fake()->numerify('86###'), 'serie_folio' => 'D' . fake()->unique()->numerify('#######'), 'sfolio' => fake()->unique()->numerify('#######'), 'nrpv' => $vin, 'owner_id' => Owner::factory(), ]; } /** * Generate a realistic VIN */ private function generateVIN(): string { $wmi = strtoupper(fake()->bothify('???')); $vds = strtoupper(fake()->bothify('??????')); $check = fake()->randomDigit(); $year = strtoupper(fake()->randomLetter()); $plant = fake()->randomDigit(); $serial = fake()->numerify('######'); return $wmi . $vds . $check . $year . $plant . $serial; } /** * Generate a Tabasco plate */ private function generatePlaca(): string { return strtoupper(fake()->bothify('???###?')); } /** * Indicate that the vehicle belongs to a specific owner. */ public function forOwner(int $ownerId): static { return $this->state(fn (array $attributes) => [ 'owner_id' => $ownerId, ]); } /** * Create an imported vehicle */ public function imported(): static { return $this->state(fn (array $attributes) => [ 'descripcion_origen' => 'IMPORTADO', ]); } /** * Create a national vehicle */ public function national(): static { return $this->state(fn (array $attributes) => [ 'descripcion_origen' => 'NACIONAL', ]); } /** * Create a vehicle without automatically creating a tag */ public function withoutTag(): static { return $this->afterCreating(function (Vehicle $vehicle) { }); } }