Browse Source

validaciones

no se pueden agregar nombres iguales de licencias
main^2
Rubi 5 days ago
parent
commit
8e4e719aa8
  1. 23
      app/Http/Controllers/TiposLicenciasController.php
  2. 14
      resources/views/tiposLicenciaCrearEditar.blade.php

23
app/Http/Controllers/TiposLicenciasController.php

@ -59,6 +59,17 @@ class TiposLicenciasController extends Controller
*/
public function store(Request $request)
{
// Verificar si ya existe un tipo de licencia con el mismo nombre
$existe = tiposLicencias::where('tipoLicencia', $request->tipoLicencia)
->where('eliminado', 1)
->exists();
if ($existe) {
return redirect()->route('tiposLicencias.create')
->with('error', 'Ya existe un tipo de licencia con el nombre "' . $request->tipoLicencia . '". Por favor, ingrese un nombre diferente.')
->withInput();
}
$tipoLicencia = new TiposLicencias();
$tipoLicencia->tipoLicencia = $request->tipoLicencia;
$tipoLicencia->eliminado = 1;
@ -81,6 +92,18 @@ class TiposLicenciasController extends Controller
*/
public function update(Request $request, $id)
{
// Verificar si ya existe otro tipo de licencia con el mismo nombre
$existe = tiposLicencias::where('tipoLicencia', $request->tipoLicencia)
->where('id', '!=', $id)
->where('eliminado', 1)
->exists();
if ($existe) {
return redirect()->route('tiposLicencias.edit', $id)
->with('error', 'Ya existe un tipo de licencia con el nombre "' . $request->tipoLicencia . '". Por favor, ingrese un nombre diferente.')
->withInput();
}
$tipoLicencia = TiposLicencias::findOrFail($id);
$tipoLicencia->tipoLicencia = $request->tipoLicencia;
if ($request->has('eliminado')) {

14
resources/views/tiposLicenciaCrearEditar.blade.php

@ -17,16 +17,12 @@
</div>
<!-- Mensajes de error -->
@if($errors->any())
<div class="mb-6 bg-red-50 border-l-4 border-red-500 p-4 rounded-r-lg">
@if(session('error'))
<div class="mb-6 bg-red-100 border-l-4 border-red-500 p-4 rounded-r-lg">
<div class="flex items-center">
<i class="fas fa-exclamation-circle text-red-500 mr-3"></i>
<div class="text-red-700">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
<i class="fas fa-exclamation-circle text-red-500 mr-3 text-xl"></i>
<div class="text-red-700 font-semibold">
{{ session('error') }}
</div>
</div>
</div>

Loading…
Cancel
Save