g
This commit is contained in:
@@ -13,18 +13,18 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('products', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->enum('type', ['bike', 'accessory', 'clothing', 'service']);
|
||||
$table->enum('type', ['bike', 'accessory', 'clothing', 'spare']); // Tipo de producto
|
||||
//$table->string('name');
|
||||
//$table->string('sku')->unique()->nullable(); // Código de barras o interno
|
||||
$table->text('description')->nullable();
|
||||
$table->text('name')->nullable();
|
||||
|
||||
$table->decimal('price', 10, 2); // Precio venta
|
||||
$table->decimal('cost', 10, 2)->nullable(); // Costo (solo admin)
|
||||
|
||||
$table->integer('stock_quantity')->default(0);
|
||||
$table->integer('min_stock_alert'); // Alerta
|
||||
$table->integer('stock_quantity')->default(100);
|
||||
$table->integer('min_stock_alert')->default(5); // Alerta
|
||||
|
||||
|
||||
$table->enum('type', ['bike', 'accessory', 'clothing', 'spare']); // Tipo de producto
|
||||
$table->string('serial_number')->nullable(); // Solo para bicis
|
||||
|
||||
$table->foreignId('suppliers_id')->constrained()->default(1);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Product;
|
||||
use App\Models\Supplier; // <-- Importamos el modelo de proveedor
|
||||
|
||||
class ProductosInicialesSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// 1. Creamos el proveedor por defecto (ID 1) para que no falle la llave foránea
|
||||
Supplier::firstOrCreate(
|
||||
['id' => 1],
|
||||
[
|
||||
'name' => 'Proveedor 1',
|
||||
'phone' => '123456789',
|
||||
'email' => 'proveedor1@example.com'
|
||||
]
|
||||
);
|
||||
|
||||
// 2. Tus datos convertidos a un array nativo de PHP
|
||||
$productos = [
|
||||
['type' => 'clothing', 'name' => 'MALLAS CORTAS indubike', 'cost' => 3920, 'price' => 4900],
|
||||
['type' => 'clothing', 'name' => 'Malla corta ITOKU', 'cost' => 3920, 'price' => 4900],
|
||||
['type' => 'clothing', 'name' => 'MALLAS CON TIRADORES', 'cost' => 4640, 'price' => 5800],
|
||||
['type' => 'clothing', 'name' => 'MALLA SQUADRA', 'cost' => 4640, 'price' => 5800],
|
||||
['type' => 'clothing', 'name' => 'CALZA LARGA C/BADANA TERMICA', 'cost' => 3280, 'price' => 4100],
|
||||
['type' => 'clothing', 'name' => 'CALZA LARGA S/ BADANA', 'cost' => 3280, 'price' => 4100],
|
||||
['type' => 'clothing', 'name' => 'ABRIGO DE PIERNAS', 'cost' => 1504, 'price' => 1880],
|
||||
['type' => 'clothing', 'name' => 'CHALECO ITOKU', 'cost' => 1520, 'price' => 1900],
|
||||
['type' => 'clothing', 'name' => 'Camiseta argentina azul', 'cost' => 1680, 'price' => 2100],
|
||||
['type' => 'clothing', 'name' => 'Camiseta itoko', 'cost' => 1680, 'price' => 2100],
|
||||
['type' => 'clothing', 'name' => 'CAMISETA INDUBIKE', 'cost' => 1680, 'price' => 2100],
|
||||
['type' => 'clothing', 'name' => 'CAMISETA SIDI', 'cost' => 3120, 'price' => 3900],
|
||||
['type' => 'clothing', 'name' => 'CAMISETA LIMA', 'cost' => 3120, 'price' => 3900],
|
||||
['type' => 'clothing', 'name' => 'CAMPERA SIDI INDUBIQUE', 'cost' => 3040, 'price' => 3800],
|
||||
['type' => 'clothing', 'name' => 'CAMPERA SQUADRA', 'cost' => 3040, 'price' => 3800],
|
||||
['type' => 'clothing', 'name' => 'CAMPERAS solbike', 'cost' => 3040, 'price' => 3800],
|
||||
['type' => 'clothing', 'name' => 'CAMPERA ITUKO', 'cost' => 3040, 'price' => 3800],
|
||||
['type' => 'clothing', 'name' => 'campera licra especial indubike', 'cost' => 3040, 'price' => 3800],
|
||||
['type' => 'clothing', 'name' => 'ROMPEBIENTO ITUKO', 'cost' => 1520, 'price' => 1900],
|
||||
['type' => 'clothing', 'name' => 'REMERA TERMICA NEGRA', 'cost' => 1520, 'price' => 1900],
|
||||
['type' => 'clothing', 'name' => 'GUANTES LICRA ECONOMICOS', 'cost' => 1520, 'price' => 1900],
|
||||
['type' => 'clothing', 'name' => 'GUANTES EXTREMO', 'cost' => 2240, 'price' => 2800],
|
||||
['type' => 'clothing', 'name' => 'GUANTES', 'cost' => 2240, 'price' => 2800],
|
||||
['type' => 'clothing', 'name' => 'GUANTES COACH', 'cost' => 2240, 'price' => 2800],
|
||||
['type' => 'clothing', 'name' => 'GUANTES DE NIÑO RECREO', 'cost' => 2240, 'price' => 2800],
|
||||
['type' => 'clothing', 'name' => 'GUANTES VAIRO', 'cost' => 2240, 'price' => 2800],
|
||||
['type' => 'clothing', 'name' => 'GUANTES CON DEDOS', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'accessory', 'name' => 'BOLSA BAJO ASIENTO EXT CHICA', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'accessory', 'name' => 'BOLSA BAJO ASIENTO GRANDE', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'accessory', 'name' => 'BOLSA TRIANGULO', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'accessory', 'name' => 'PORTA CELULAR', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'CASCO ECONOMICO 10V', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'CASCO 20 V', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'CASCO 22V D CARRERA', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'CASCO DE NIÑO', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'casco masz1', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'Cascos de niña con rodilleras rosa', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'CASCO BMK ASFALTOCCCC', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'Casco de BMX roler/scate', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'clothing', 'name' => 'Cascos de niño chico (3 años)', 'cost' => 2640, 'price' => 3300],
|
||||
['type' => 'accessory', 'name' => 'ALFORJA', 'cost' => 2640, 'price' => 3300],
|
||||
];
|
||||
|
||||
// 3. Insertamos usando updateOrCreate para no duplicar si lo corrés dos veces
|
||||
foreach ($productos as $item) {
|
||||
Product::updateOrCreate(
|
||||
['name' => $item['name']], // Busca por descripcion
|
||||
[
|
||||
'type' => $item['type'],
|
||||
'cost' => $item['cost'],
|
||||
'price' => $item['price'],
|
||||
'stock_quantity' => 100, // Inicia con stock por defecto
|
||||
'min_stock_alert' => 5, // Alerta por defecto
|
||||
'suppliers_id' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$this->command->info('¡Productos y proveedor insertados correctamente!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user