Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

crea funciones de migracion de laravel para cada una de estas tablas 1. Tabla…

  1. User

    crea funciones de migracion de laravel para cada una de estas tablas

    1. Tabla “Clientes”:
    • ID_Cliente (clave primaria)
    • Nombre
    • Dirección
    • Teléfono
    1. Tabla “Productos”:
    • ID_Producto (clave primaria)
    • Nombre
    • Descripción
    • Precio
    1. Tabla “Categorías”:
    • ID_Categoría (clave primaria)
    • Nombre
    1. Tabla “Pedidos”:
    • ID_Pedido (clave primaria)
    • ID_Cliente (clave foránea de la tabla Clientes)
    • Fecha
    • Estado (por ejemplo: pendiente, en proceso, entregado)
    1. Tabla “Detalle_Pedido”:
    • ID_Detalle_Pedido (clave primaria)
    • ID_Pedido (clave foránea de la tabla Pedidos)
    • ID_Producto (clave foránea de la tabla Productos)
    • Cantidad
    1. Tabla “Empleados”:
    • ID_Empleado (clave primaria)
    • Nombre
    • Cargo
    • Teléfono
    1. Tabla “Facturas”:
    • ID_Factura (clave primaria)
    • ID_Pedido (clave foránea de la tabla Pedidos)
    • Fecha
    • Total
  2. Assistant

    Para la migración de estas tablas en Laravel, puedes utilizar el siguiente código:

    1. Migración de la tabla "Clientes":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateClientesTable extends Migration
    {
        public function up()
        {
            Schema::create('clientes', function (Blueprint $table) {
                $table->increments('id_cliente');
                $table->string('nombre');
                $table->string('direccion');
                $table->string('telefono');
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('clientes');
        }
    }
    
    1. Migración de la tabla "Productos":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateProductosTable extends Migration
    {
        public function up()
        {
            Schema::create('productos', function (Blueprint $table) {
                $table->increments('id_producto');
                $table->string('nombre');
                $table->text('descripcion');
                $table->decimal('precio', 8, 2);
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('productos');
        }
    }
    
    1. Migración de la tabla "Categorías":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateCategoriasTable extends Migration
    {
        public function up()
        {
            Schema::create('categorias', function (Blueprint $table) {
                $table->increments('id_categoria');
                $table->string('nombre');
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('categorias');
        }
    }
    
    1. Migración de la tabla "Pedidos":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreatePedidosTable extends Migration
    {
        public function up()
        {
            Schema::create('pedidos', function (Blueprint $table) {
                $table->increments('id_pedido');
                $table->unsignedInteger('id_cliente');
                $table->foreign('id_cliente')->references('id_cliente')->on('clientes');
                $table->date('fecha');
                $table->string('estado');
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('pedidos');
        }
    }
    
    1. Migración de la tabla "Detalle_Pedido":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateDetallePedidoTable extends Migration
    {
        public function up()
        {
            Schema::create('detalle_pedido', function (Blueprint $table) {
                $table->increments('id_detalle_pedido');
                $table->unsignedInteger('id_pedido');
                $table->foreign('id_pedido')->references('id_pedido')->on('pedidos');
                $table->unsignedInteger('id_producto');
                $table->foreign('id_producto')->references('id_producto')->on('productos');
                $table->integer('cantidad');
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('detalle_pedido');
        }
    }
    
    1. Migración de la tabla "Empleados":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateEmpleadosTable extends Migration
    {
        public function up()
        {
            Schema::create('empleados', function (Blueprint $table) {
                $table->increments('id_empleado');
                $table->string('nombre');
                $table->string('cargo');
                $table->string('telefono');
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('empleados');
        }
    }
    
    1. Migración de la tabla "Facturas":
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateFacturasTable extends Migration
    {
        public function up()
        {
            Schema::create('facturas', function (Blueprint $table) {
                $table->increments('id_factura');
                $table->unsignedInteger('id_pedido');
                $table->foreign('id_pedido')->references('id_pedido')->on('pedidos');
                $table->date('fecha');
                $table->decimal('total', 8, 2);
                $table->timestamps();
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('facturas');
        }
    }
    

    Recuerda ejecutar el comando php artisan migrate para crear las tablas en la base de datos.