100 lines
3.3 KiB
PHP
100 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Administrador;
|
|
use App\Models\CredencialProfesional;
|
|
use App\Models\Foto;
|
|
use App\Models\Persona;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class AdministradorSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$usuario = env('ADMIN_USUARIO', 'admin');
|
|
$passwordPlano = env('ADMIN_PASSWORD', 'admin1234');
|
|
$correo = env('ADMIN_CORREO', 'admin@abogadaslitoral.com');
|
|
$dni = env('ADMIN_DNI', '30000000');
|
|
$nombre = env('ADMIN_NOMBRE', 'Usuario');
|
|
$apellido = env('ADMIN_APELLIDO', 'Administrador');
|
|
$cuil = env('ADMIN_CUIL', '20-30000000-0');
|
|
$fechaNac = env('ADMIN_FECHANAC', '2026-01-01');
|
|
$preguntaSecreta = mb_strtolower(trim((string) env('ADMIN_PREGUNTA_SECRETA', 'Cual es el nombre de tu primera mascota')));
|
|
$respuestaSecreta = mb_strtolower(trim((string) env('ADMIN_RESPUESTA_SECRETA', 'admin')));
|
|
|
|
DB::transaction(function () use (
|
|
$apellido,
|
|
$correo,
|
|
$cuil,
|
|
$dni,
|
|
$fechaNac,
|
|
$nombre,
|
|
$passwordPlano,
|
|
$preguntaSecreta,
|
|
$respuestaSecreta,
|
|
$usuario
|
|
): void {
|
|
$foto = Foto::query()->firstOrCreate(
|
|
['ruta' => 'images/avatar_default.png'],
|
|
[
|
|
'extension' => 'png',
|
|
'nombre' => 'avatar_default',
|
|
'mime_type' => 'image/png',
|
|
'tamanio_bytes' => 136788,
|
|
]
|
|
);
|
|
|
|
$persona = Persona::query()->updateOrCreate(
|
|
['dni' => $dni],
|
|
[
|
|
'nombre' => $nombre,
|
|
'apellido' => $apellido,
|
|
'cuil' => $cuil,
|
|
'fechanac' => $fechaNac,
|
|
'foto_id' => $foto->id,
|
|
]
|
|
);
|
|
|
|
$credencial = CredencialProfesional::query()->updateOrCreate(
|
|
['usuario' => $usuario],
|
|
[
|
|
'contra' => Hash::make($passwordPlano),
|
|
'rol' => 'ADMIN',
|
|
]
|
|
);
|
|
|
|
$administrador = Administrador::query()
|
|
->where('persona_id', $persona->id)
|
|
->orWhere('dni', $dni)
|
|
->first();
|
|
|
|
if ($administrador) {
|
|
$administrador->update([
|
|
'persona_id' => $persona->id,
|
|
'dni' => $dni,
|
|
'correo' => $correo,
|
|
'pregunta_secreta_hash' => $preguntaSecreta,
|
|
'respuesta_secreta_hash' => Hash::make($respuestaSecreta),
|
|
'credencialprofesional_id' => $credencial->id,
|
|
]);
|
|
|
|
return;
|
|
}
|
|
|
|
Administrador::query()->create([
|
|
'persona_id' => $persona->id,
|
|
'dni' => $dni,
|
|
'correo' => $correo,
|
|
'pregunta_secreta_hash' => $preguntaSecreta,
|
|
'respuesta_secreta_hash' => Hash::make($respuestaSecreta),
|
|
'credencialprofesional_id' => $credencial->id,
|
|
]);
|
|
});
|
|
}
|
|
} |