Estructura de base de datos, migraciones, factories y seeders

This commit is contained in:
Lucho
2026-06-24 16:28:01 -03:00
parent 317d85b5c3
commit c81120f2e3
42 changed files with 1033 additions and 298 deletions
+13 -1
View File
@@ -6,6 +6,7 @@ use App\Models\Cliente;
use App\Models\CredencialCliente;
use App\Models\Persona;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Cliente>
@@ -30,8 +31,19 @@ class ClienteFactory extends Factory
'dni' => (string) $this->faker->unique()->numberBetween(20000000, 45000000),
'correo' => $this->faker->unique()->safeEmail(),
'persona_id' => Persona::factory(),
'baja_id' => null,
'baja_id' => 1,
'credencialcliente_id' => CredencialCliente::factory(),
];
}
public function configure(): static
{
return $this->afterCreating(function (Cliente $cliente) {
CredencialCliente::where('id', $cliente->credencialcliente_id)
->update([
'correo' => $cliente->correo,
'contra' => Hash::make($cliente->dni),
]);
});
}
}
@@ -28,7 +28,7 @@ class CredencialProfesionalFactory extends Factory
return [
'usuario' => $this->faker->unique()->userName(),
'contra' => Hash::make('password'),
'rol' => $this->faker->randomElement(['Administrador', 'Profesional']),
'rol' => 'Profesional',
'token' => null,
'fecha_hora' => null,
];
+11 -1
View File
@@ -29,13 +29,23 @@ class PersonaFactory extends Factory
$cuilPrefix = $this->faker->randomElement(['20', '27']);
$cuilSuffix = $this->faker->numberBetween(0, 9);
$fotoDefault = Foto::firstOrCreate(
['ruta' => 'images/avatar_default.png'],
[
'extension' => 'png',
'tamanio_bytes' => 136788,
'nombre' => 'avatar_default',
'mime_type' => 'image/png',
]
);
return [
'dni' => (string) $dni,
'nombre' => $this->faker->firstName(),
'apellido' => $this->faker->lastName(),
'cuil' => "{$cuilPrefix}{$dni}{$cuilSuffix}",
'fechanac' => $this->faker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'),
'foto_id' => Foto::factory(),
'foto_id' => $fotoDefault->id,
];
}
}
+9 -3
View File
@@ -3,7 +3,6 @@
namespace Database\Factories;
use App\Models\CredencialProfesional;
use App\Models\EstadoProfesional;
use App\Models\Persona;
use App\Models\Profesional;
use App\Models\Profesion;
@@ -35,8 +34,15 @@ class ProfesionalFactory extends Factory
'persona_id' => Persona::factory(),
'profesion_id' => Profesion::factory(),
'credencialprofesional_id' => CredencialProfesional::factory(),
'estadoprofesional_id' => EstadoProfesional::factory(),
'baja_id' => null,
'baja_id' => 1,
];
}
public function configure(): static
{
return $this->afterCreating(function (Profesional $profesional) {
CredencialProfesional::where('id', $profesional->credencialprofesional_id)
->update(['usuario' => $profesional->dni . '-' . $profesional->profesion_id]);
});
}
}
+20 -2
View File
@@ -2,8 +2,11 @@
namespace Database\Factories;
use App\Models\Foto;
use App\Models\Servicio;
use App\Models\Profesion;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\DB;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Servicio>
@@ -24,9 +27,24 @@ class ServicioFactory extends Factory
*/
public function definition(): array
{
$fotoDefault = Foto::firstOrCreate(
['ruta' => 'images/Servicio.jpg'],
[
'extension' => 'jpg',
'tamanio_bytes' => 0,
'nombre' => 'Servicio',
'mime_type' => 'image/jpeg',
]
);
return [
'nombre' => $this->faker->words(3, true),
'descripcion' => $this->faker->sentence(12),
'titulo' => $this->faker->unique()->bs(),
'estado' => 'activo',
'descripcion' => $this->faker->sentence(12),
'visibleenweb' => 'si',
'contenidoweb_id' => DB::table('contenidoswebs')->value('id'),
'profesion_id' => Profesion::factory(),
'foto_id' => $fotoDefault->id,
];
}
}