sergiomarquez778 4 weeks ago
parent
commit
88a7eac1ba
  1. 12
      app/Http/Controllers/DocentesController.php
  2. 96
      app/Http/Controllers/TiposVeiculosController.php
  3. 14
      app/Models/tiposVeiculos.php
  4. 24
      database/factories/TiposVeiculosFactory.php
  5. 28
      database/migrations/2025_03_06_162928_create_tipos_veiculos_table.php
  6. 17
      database/seeders/TiposVeiculosSeeder.php
  7. 92
      resources/views/docentes.blade.php
  8. 216
      resources/views/docentesCrearEditar.blade.php
  9. 6
      resources/views/layouts/dashboard.blade.php
  10. 134
      resources/views/vehiculos.blade.php
  11. 135
      resources/views/vehiculosCrearEditar.blade.php
  12. 2
      routes/web.php

12
app/Http/Controllers/DocentesController.php

@ -32,7 +32,7 @@ class DocentesController extends Controller
{
$docente = new Docentes($request->all());
$docente->save();
return redirect()->route('docente.index')->with('success', 'Docente creado exitosamente.');
return redirect()->route('docentes.index')->with('success', 'Docente creado exitosamente.');
}
/**
* Display the specified resource.
@ -47,8 +47,9 @@ class DocentesController extends Controller
*/
public function edit($id)
{
$docentes = Docentes::all();
$docente = Docentes::find($id);
return view('docentesCrearEditar', ['docentes' => $docentes, 'docente' => $docente]);
}
/**
@ -57,9 +58,8 @@ class DocentesController extends Controller
public function update(Request $request, $id)
{
$docente = Docentes::find($id);
$docente->fill($request->all());
$docente->save();
return redirect()->route('docente.index')->with('success', 'Docente actualizado correctamente');
$docente->update($request->all());
return redirect()->route('docentes.index')->with('success', 'Docente actualizado correctamente');
}
/**
@ -69,6 +69,6 @@ class DocentesController extends Controller
{
$docente = Docentes::find($id);
$docente->delete();
return redirect()->route('docente.index')->with('success', 'Docente eliminado correctamente');
return redirect()->route('docentes.index')->with('success', 'Docente eliminado correctamente');
}
}

96
app/Http/Controllers/TiposVeiculosController.php

@ -0,0 +1,96 @@
<?php
namespace App\Http\Controllers;
use App\Models\tiposVeiculos;
use Illuminate\Http\Request;
class TiposVeiculosController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$busqueda = $request->busqueda;
if($busqueda) {
$tiposVeiculos = tiposVeiculos::where('nombre', 'LIKE', "%{$busqueda}%")->get();
if($tiposVeiculos->count() == 0) {
return redirect()->route('tiposVeiculos.index')
->with('error', value: 'No existe ningun tipo de vehiculo con el nombre "' . $busqueda . '". Por favor, inténtalo de nuevo.');
}
// Si solo hay una marca, mostrar sus detalles
if($tiposVeiculos->count() == 1) {
$tiposVeiculos = $tiposVeiculos->first();
return redirect()->route('vehiculos.edit', $tiposVeiculos->id);
}
// Si hay múltiples coincidencias, mostrar la lista filtrada
return view('vehiculos', ["tiposVeiculos" => $tiposVeiculos]);
}
// Si no hay búsqueda, mostrar todas las marcas
$tiposVeiculos = tiposVeiculos::all();
return view('vehiculos', ["tiposVeiculos" => $tiposVeiculos]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$tiposVeiculos = tiposVeiculos::all();
return view('vehiculosCrearEditar',['tiposVeiculos'=>$tiposVeiculos]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$tiposVeiculos = new tiposVeiculos($request->all());
$tiposVeiculos->save();
return redirect()->route('vehiculos.index')->with('success', 'Tipo de vehiculo creado exitosamente.');
}
/**
* Display the specified resource.
*/
public function show(tiposVeiculos $tiposVeiculos)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$tiposVeiculos = tiposVeiculos::find($id);
return view('vehiculosCrearEditar',['tiposVeiculos'=>$tiposVeiculos]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$tiposVeiculos = tiposVeiculos::find($id);
$tiposVeiculos->fill($request->all());
$tiposVeiculos->save();
return redirect()->route('vehiculos.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$tiposVeiculos = tiposVeiculos::find($id);
$tiposVeiculos->delete();
return redirect()->route('vehiculos.index')->with('success', 'Vehiculo eliminado exitosamente.');
}
}

14
app/Models/tiposVeiculos.php

@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class tiposVeiculos extends Model
{
use HasFactory;
protected $fillable = [
'nombre',
];
}

24
database/factories/TiposVeiculosFactory.php

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\tiposVeiculos>
*/
class TiposVeiculosFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
"nombre"=> $this->faker->name(),
//
];
}
}

28
database/migrations/2025_03_06_162928_create_tipos_veiculos_table.php

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tipos_veiculos', function (Blueprint $table) {
$table->id();
$table->string('nombre');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tipos_veiculos');
}
};

17
database/seeders/TiposVeiculosSeeder.php

@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class TiposVeiculosSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}

92
resources/views/docentes.blade.php

@ -1,4 +1,4 @@
{{-- Start of Selection --}}
<!-- Start Generation Here -->
@extends('layouts.dashboard')
@section('content')
@ -19,8 +19,10 @@
<div class="bg-white rounded-lg shadow-lg">
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
<h2 class="text-2xl font-bold">Gestión de Docentes</h2>
<a href="{{ route('docentes.create') }}" class="px-4 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600">
Crear Docente
<a href="{{ route('docentes.create') }}"
class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 flex items-center gap-2">
<i class="fas fa-plus"></i>
Agregar
</a>
</div>
@ -38,7 +40,7 @@
</div>
</div>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
Buscar
Buscar/Actualizar
</button>
@if(request('busqueda'))
<a href="{{ route('docentes.index') }}" class="px-4 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600">
@ -54,44 +56,40 @@
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nombre</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Teléfono</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Correo</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tipo de Licencia</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Materia</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@if($docentes->isEmpty())
<tr>
<td colspan="7" class="px-6 py-4 text-center text-gray-500">No hay docentes registrados.</td>
</tr>
@else
@foreach($docentes as $docente)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->id }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->nombre }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->telefono }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->correo }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->tipo_licencia }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ $docente->materia }}</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex gap-2">
<a href="{{ route('docentes.edit', $docente->id) }}" class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i> <!-- Icono de edición -->
</a>
<form action="{{ route('docentes.destroy', $docente->id) }}" method="POST" class="inline" onsubmit="return false;">
@csrf
@method('DELETE')
<button type="button" onclick="confirmarEliminacion(this)" class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i> <!-- Icono de eliminación -->
</button>
</form>
</div>
</td>
</tr>
@endforeach
@endif
@foreach($docentes as $docente)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $docente->id }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<i class="fas fa-user text-blue-500 mr-2"></i>
{{ $docente->nombre }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex gap-2">
<a href="#"
onclick="confirmarEdicion('{{ route('docentes.edit', $docente->id) }}')"
class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('docentes.destroy', $docente->id) }}"
method="POST"
class="inline"
onsubmit="return false;">
@csrf
@method('DELETE')
<button type="button"
onclick="confirmarEliminacion(this)"
class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@ -99,6 +97,22 @@
</div>
<script>
function confirmarEdicion(url) {
Swal.fire({
title: '¿Editar docente?',
text: "¿Estás seguro de que deseas editar este docente?",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí, editar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = url;
}
});
}
function confirmarEliminacion(button) {
Swal.fire({
title: '¿Estás seguro?',
@ -118,4 +132,4 @@ function confirmarEliminacion(button) {
}
</script>
@endsection
{{-- End of Selection --}}
<!-- End Generation Here -->

216
resources/views/docentesCrearEditar.blade.php

@ -2,45 +2,191 @@
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white rounded-lg shadow-lg">
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
<h2 class="text-2xl font-bold">{{ isset($docente) ? 'Editar Docente' : 'Crear Docente' }}</h2>
</div>
<div class="p-4">
<form action="{{ isset($docente) ? route('docente.update', $docente->id) : route('docente.store') }}" method="POST">
@csrf
@if(isset($docente))
@method('PUT')
@endif
<div class="grid grid-cols-1 gap-6">
<div>
<label for="nombre" class="block text-sm font-medium text-gray-700">Nombre</label>
<input type="text" name="nombre" id="nombre" value="{{ old('nombre', $docente->nombre ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="telefono" class="block text-sm font-medium text-gray-700">Teléfono</label>
<input type="text" name="telefono" id="telefono" value="{{ old('telefono', $docente->telefono ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="correo" class="block text-sm font-medium text-gray-700">Correo</label>
<input type="email" name="correo" id="correo" value="{{ old('correo', $docente->correo ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="tipo_licencia" class="block text-sm font-medium text-gray-700">Tipo de Licencia</label>
<input type="text" name="tipo_licencia" id="tipo_licencia" value="{{ old('tipo_licencia', $docente->tipo_licencia ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="materia" class="block text-sm font-medium text-gray-700">Materia</label>
<input type="text" name="materia" id="materia" value="{{ old('materia', $docente->materia ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<div class="max-w-lg mx-auto">
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
<div class="p-6">
<!-- Encabezado del formulario -->
<div class="flex items-center justify-between mb-6">
<h2 class="text-2xl font-bold text-gray-800">
{{ isset($docente) ? 'Editar Docente' : 'Nuevo Docente' }}
</h2>
<div class="h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center">
<i class="fas fa-user text-blue-600"></i>
</div>
</div>
<div class="mt-6 flex justify-end">
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
{{ isset($docente) ? 'Actualizar' : 'Crear' }}
</button>
<!-- Mensajes de error -->
@if($errors->any())
<div class="mb-6 bg-red-50 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>
</div>
</div>
</div>
</form>
@endif
<!-- Formulario -->
<form id="docenteForm"
action="{{ isset($docente) ? route('docentes.update', $docente->id) : route('docentes.store') }}"
method="POST">
@csrf
@if(isset($docente))
@method('PUT')
@endif
<div class="space-y-6">
<!-- Campo Nombre -->
<div>
<label for="nombre" class="block text-sm font-medium text-gray-700 mb-2">
Nombre del Docente
</label>
<div class="relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fas fa-user text-gray-400"></i>
</div>
<input type="text"
name="nombre"
id="nombre"
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($docente) ? $docente->nombre : old('nombre') }}"
placeholder="Ingrese el nombre del docente"
required>
</div>
@error('nombre')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Campo Teléfono -->
<div>
<label for="telefono" class="block text-sm font-medium text-gray-700 mb-2">
Teléfono
</label>
<input type="text"
name="telefono"
id="telefono"
class="block w-full border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($docente) ? $docente->telefono : old('telefono') }}"
placeholder="Ingrese el teléfono del docente"
required>
</div>
<!-- Campo Correo -->
<div>
<label for="correo" class="block text-sm font-medium text-gray-700 mb-2">
Correo Electrónico
</label>
<input type="email"
name="correo"
id="correo"
class="block w-full border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($docente) ? $docente->correo : old('correo') }}"
placeholder="Ingrese el correo del docente"
required>
</div>
<!-- Campo Tipo de Licencia -->
<div>
<label for="tipo_licencia" class="block text-sm font-medium text-gray-700 mb-2">
Tipo de Licencia
</label>
<input type="text"
name="tipo_licencia"
id="tipo_licencia"
class="block w-full border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($docente) ? $docente->tipo_licencia : old('tipo_licencia') }}"
placeholder="Ingrese el tipo de licencia del docente"
required>
</div>
<!-- Campo Materia -->
<div>
<label for="materia" class="block text-sm font-medium text-gray-700 mb-2">
Materia
</label>
<input type="text"
name="materia"
id="materia"
class="block w-full border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($docente) ? $docente->materia : old('materia') }}"
placeholder="Ingrese la materia que imparte"
required>
</div>
<!-- Botones de acción -->
<div class="flex justify-end space-x-2 pt-4 border-t border-gray-200">
<a href="{{ route('docentes.index') }}"
class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
Cancelar
</a>
<button type="button"
onclick="confirmarAccion()"
class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
{{ isset($docente) ? 'Actualizar' : 'Guardar' }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function confirmarAccion() {
const esEdicion = {{ isset($docente) ? 'true' : 'false' }};
const nombre = document.getElementById('nombre').value.trim();
if (!nombre) {
Swal.fire({
title: 'Error',
text: 'El nombre del docente es obligatorio',
icon: 'error',
confirmButtonColor: '#3085d6',
confirmButtonText: 'Entendido'
});
return;
}
Swal.fire({
title: esEdicion ? '¿Editar docente?' : '¿Guardar docente?',
html: esEdicion ?
`¿Estás seguro de editar al docente:<br><strong>${nombre}</strong>?` :
`¿Estás seguro de guardar al docente:<br><strong>${nombre}</strong>?`,
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: esEdicion ? 'Sí, editar' : 'Sí, guardar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
document.getElementById('docenteForm').submit();
}
});
}
// Prevenir envío del formulario con Enter
document.getElementById('docenteForm').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
confirmarAccion();
}
});
// Focus en el campo nombre al cargar la página
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('nombre').focus();
});
</script>
@endsection

6
resources/views/layouts/dashboard.blade.php

@ -79,9 +79,9 @@
<!-- Tipos -->
<li>
<a href="/configuracion/tipos" class="flex items-center space-x-2 px-4 py-2 rounded hover:bg-blue-700">
<i class="fas fa-tags"></i>
<span>Tipos</span>
<a href="{{ route('vehiculos.index') }}" class="flex items-center space-x-2 px-4 py-2 rounded hover:bg-blue-700">
<i class="fas fa-car"></i>
<span>Tipos de Vehiculos</span>
</a>
</li>

134
resources/views/vehiculos.blade.php

@ -0,0 +1,134 @@
@extends('layouts.dashboard')
@section('content')
<div class="container mx-auto px-4 py-6">
<!-- Encabezado -->
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
<span class="block sm:inline">{{ session('success') }}</span>
</div>
@endif
@if(session('error'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
<span class="block sm:inline">{{ session('error') }}</span>
</div>
@endif
<div class="bg-white rounded-lg shadow-lg">
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
<h2 class="text-2xl font-bold">Gestión de Vehículos</h2>
<a href="{{ route('vehiculos.create') }}"
class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 flex items-center gap-2">
<i class="fas fa-plus"></i>
Agregar
</a>
</div>
<!-- Barra de búsqueda -->
<div class="p-4 border-b border-gray-200 bg-gray-50">
<form action="{{ route('vehiculos.index') }}" method="GET" class="flex gap-2">
<div class="relative w-full sm:w-64">
<input type="text"
name="busqueda"
placeholder="Buscar vehículo..."
value="{{ request('busqueda') }}"
class="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<div class="absolute left-3 top-2.5 text-gray-400">
<i class="fas fa-search"></i>
</div>
</div>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
Buscar/Actualizar
</button>
@if(request('busqueda'))
<a href="{{ route('vehiculos.index') }}" class="px-4 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600">
Limpiar
</a>
@endif
</form>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Vehículo</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($tiposVeiculos as $vehiculo)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $vehiculo->id }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<i class="fas fa-car text-blue-500 mr-2"></i>
{{ $vehiculo->nombre }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex gap-2">
<a href="#"
onclick="confirmarEdicion('{{ route('vehiculos.edit', $vehiculo->id) }}')"
class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('vehiculos.destroy', $vehiculo->id) }}"
method="POST"
class="inline"
onsubmit="return false;">
@csrf
@method('DELETE')
<button type="button"
onclick="confirmarEliminacion(this)"
class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
<script>
function confirmarEdicion(url) {
Swal.fire({
title: '¿Editar vehículo?',
text: "¿Estás seguro de que deseas editar este vehículo?",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí, editar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = url;
}
});
}
function confirmarEliminacion(button) {
Swal.fire({
title: '¿Estás seguro?',
text: "Esta acción no se puede deshacer",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí, eliminar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
button.closest('form').onsubmit = null;
button.closest('form').submit();
}
});
}
</script>
@endsection

135
resources/views/vehiculosCrearEditar.blade.php

@ -0,0 +1,135 @@
@extends('layouts.dashboard')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="max-w-lg mx-auto">
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
<div class="p-6">
<!-- Encabezado del formulario -->
<div class="flex items-center justify-between mb-6">
<h2 class="text-2xl font-bold text-gray-800">
{{ isset($tipoVehiculo) ? 'Editar Vehículo' : 'Nuevo Vehículo' }}
</h2>
<div class="h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center">
<i class="fas fa-car text-blue-600"></i>
</div>
</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">
<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>
</div>
</div>
</div>
@endif
<!-- Formulario -->
<form id="tipoVehiculoForm"
action="{{ isset($tipoVehiculo) ? route('vehiculos.update', $tipoVehiculo->id) : route('vehiculos.store') }}"
method="POST">
@csrf
@if(isset($tipoVehiculo))
@method('PUT')
@endif
<div class="space-y-6">
<!-- Campo Nombre -->
<div>
<label for="nombre" class="block text-sm font-medium text-gray-700 mb-2">
Nombre del Vehículo
</label>
<div class="relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fas fa-car text-gray-400"></i>
</div>
<input type="text"
name="nombre"
id="nombre"
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
value="{{ isset($tipoVehiculo) ? $tipoVehiculo->nombre : old('nombre') }}"
placeholder="Ingrese el nombre del vehículo"
required>
</div>
@error('nombre')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Botones de acción -->
<div class="flex justify-end space-x-2 pt-4 border-t border-gray-200">
<a href="{{ route('vehiculos.index') }}"
class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
Cancelar
</a>
<button type="button"
onclick="confirmarAccion()"
class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
{{ isset($tipoVehiculo) ? 'Actualizar' : 'Guardar' }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function confirmarAccion() {
const esEdicion = {{ isset($tipoVehiculo) ? 'true' : 'false' }};
const nombre = document.getElementById('nombre').value.trim();
if (!nombre) {
Swal.fire({
title: 'Error',
text: 'El nombre del vehículo es obligatorio',
icon: 'error',
confirmButtonColor: '#3085d6',
confirmButtonText: 'Entendido'
});
return;
}
Swal.fire({
title: esEdicion ? '¿Editar vehículo?' : '¿Guardar vehículo?',
html: esEdicion ?
`¿Estás seguro de editar el vehículo:<br><strong>${nombre}</strong>?` :
`¿Estás seguro de guardar el vehículo:<br><strong>${nombre}</strong>?`,
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: esEdicion ? 'Sí, editar' : 'Sí, guardar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
document.getElementById('tipoVehiculoForm').submit();
}
});
}
// Prevenir envío del formulario con Enter
document.getElementById('tipoVehiculoForm').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
confirmarAccion();
}
});
// Focus en el campo nombre al cargar la página
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('nombre').focus();
});
</script>
@endsection

2
routes/web.php

@ -5,6 +5,7 @@ use App\Http\Controllers\usuariosController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\MarcaController;
use App\Http\Controllers\DocentesController;
use App\Http\Controllers\TiposVeiculosController;
/*
|--------------------------------------------------------------------------
| Web Routes
@ -24,6 +25,7 @@ Auth::routes(['register'=>true,'reset'=>false]);
Route::resource('marca', MarcaController::class);
Route::resource('docentes', DocentesController::class);
Route::resource('vehiculos', TiposVeiculosController::class);
// Rutas protegidas que requieren autenticación
Route::middleware(['auth'])->group(function () {

Loading…
Cancel
Save