Files
LauckCycles/database/factories/ProductFactory.php
T

56 lines
2.3 KiB
PHP

<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product>
*/
class ProductFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$brands = ['Shimano', 'Venzo', 'Trek', 'Specialized', 'Maxxis', 'Sram', 'Raleigh'];
$bikeModels = ['Loki', 'Marlin 5', 'Chisel', 'Talon 3', 'Aspect 950'];
$accessories = ['Guantes Grip', 'Calco Reflectora', 'Coderas', 'Rodilleras', 'Casco MTB', 'Luz Delantera USB', 'Cubierta Kevlar'];
$spareParts = ['Manubrio', 'Pedales Aluminio', 'Cámara 29"', 'Rayos x50', 'Disco de Freno', 'Cable de Freno', 'Asiento Goma', 'Cadena 9v'];
$cats = ['Pro', 'Basic', 'Comp', 'Elite'];
$type = $this->faker->randomElement(['bike', 'accessory', 'clothing', 'spare']);
// Generar nombre según el tipo
if ($type === 'bike') {
$name = $this->faker->randomElement($brands) . ' ' . $this->faker->randomElement($bikeModels);
} elseif ($type === 'accessory') {
$name = $this->faker->randomElement($accessories) .' '. $this->faker->randomElement($cats);
} elseif ($type === 'clothing') {
$name = $this->faker->randomElement(['Remera', 'Pantalon', 'Casco', 'Coderas', 'Guantes']).' '.$this->faker->randomElement($cats);
} else {
$name = $this->faker->randomElement($spareParts) .' '. $this->faker->randomElement($cats);
}
// Lógica de Precios
$price = $this->faker->numberBetween(5000, 200000);
$cost = $price * $this->faker->randomFloat(2, 0.1, 0.8);
return [
'name' => $name,
'sku' => strtoupper($this->faker->bothify('???-#####')),
'description' => $this->faker->sentence(10),
'price' => $price,
'cost' => $cost,
'stock_quantity' => $type === 'service' ? 0 : $this->faker->numberBetween(0, 50),
'min_stock_alert' => $this->faker->numberBetween(2, 10),
'type' => $type,
// Nro de serie si es bicicleta
'serial_number' => $type === 'bike' ? strtoupper($this->faker->bothify('##??##??')) : null,
'suppliers_id'=> 1
];
}
}