generarIskUnico($contexto); $this->insert(['isk' => $isk]); return $isk; } /** * Genera un ISK único validado contra la base de datos. */ private function generarIskUnico(string $contexto): string { do { $isk = $this->generarIsk($contexto); } while ($this->where('isk', $isk)->countAllResults() > 0); return $isk; } /** * Formato legible de ISK, ejemplo: isk_libro_20250419_ab12c */ private function generarIsk(string $contexto): string { $fecha = date('Ymd'); $random = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789'), 0, 5); return "isk_{$contexto}_{$fecha}_{$random}"; } /** * Hook para generar el ISK automáticamente al insertar. */ protected function agregarIsk(array $data): array { if (!isset($data['data']['isk']) || empty($data['data']['isk'])) { $data['data']['isk'] = $this->generarIskUnico('registro'); } return $data; } // Bloqueo total de eliminaciones public function delete($id = null, bool $purge = false) { throw new RuntimeException('La eliminación de registros está deshabilitada.'); } public function deleteWhere($where) { throw new RuntimeException('La eliminación de registros está deshabilitada.'); } public function deleteBatch($where) { throw new RuntimeException('La eliminación de registros está deshabilitada.'); } }