ejemplo de migracion laravel regla de oro para crear una buena migracion
Tue Jun 09 2026 20:25:20 GMT+0000 (Coordinated Universal Time)
Saved by
@jrg_300i
Resumen del estándar IRPAT guardado:
ID ($table->id())
Relaciones (foreignId('name_id')->constrained('names');))
Personal / Datos de negocio (string, date, text, etc.)
Auth (email, password, rememberToken, si aplica)
Timestamps ($table->timestamps())
ejemplo:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('personas', function (Blueprint $table) {
// I - ID (Siempre primero)
$table->id();
// R - Relaciones (Primero para evitar problemas de orden SQL)
$table->foreignId('genero_id')->constrained('generos');
$table->foreignId('estado_id')->constrained('estados');
$table->foreignId('usuario_id')->constrained('users');
// P - Personal / Datos de negocio
$table->string('nacionalidad');
$table->string('cedula')->unique();
$table->string('nombres');
$table->string('apellidos');
$table->string('email');
$table->string('telefono');
$table->date('fecha_na');
$table->string('direccion');
// A - Auth (No aplica en esta tabla, pero iría aquí si fuera necesario)
// T - Timestamps (Siempre último)
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('personas');
}
};
content_copyCOPY
Comments