diff --git a/app/Http/Controllers/CapacidadController.php b/app/Http/Controllers/CapacidadController.php new file mode 100644 index 0000000..e4caf50 --- /dev/null +++ b/app/Http/Controllers/CapacidadController.php @@ -0,0 +1,92 @@ +<?php + +namespace App\Http\Controllers; + +use App\Models\Capacidad; +use Illuminate\Http\Request; + +class CapacidadController extends Controller +{ + /** + * Display a listing of the resource. + */ + public function index(Request $request) + { + $busqueda = $request->busqueda; + + if($busqueda) { + $capacidades = Capacidad::where('cantidad', 'LIKE', "%{$busqueda}%")->get(); + + if($capacidades->count() == 0) { + return redirect()->route('capacidades.index') + ->with('error', 'No existe ninguna capacidad con la cantidad "' . $busqueda . '". Por favor, inténtalo de nuevo.'); + } + + if($capacidades->count() == 1) { + $capacidad = $capacidades->first(); + return redirect()->route('capacidades.edit', $capacidad->id); + } + + return view('capacidades', ["capacidades" => $capacidades]); + } + + $capacidades = Capacidad::all(); + return view('capacidades', ["capacidades" => $capacidades]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + return view('capacidadesCrearEditar'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $capacidad = new Capacidad($request->all()); + $capacidad->save(); + return redirect()->route('capacidades.index')->with('success', 'Capacidad creada exitosamente.'); + } + + /** + * Display the specified resource. + */ + public function show(Capacidad $capacidad) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + $capacidad = Capacidad::find($id); + return view('capacidadesCrearEditar', ['capacidad' => $capacidad]); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id) + { + $capacidad = Capacidad::find($id); + $capacidad->fill($request->all()); + $capacidad->save(); + return redirect()->route('capacidades.index')->with('success', 'Capacidad actualizada exitosamente.'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + $capacidad = Capacidad::find($id); + $capacidad->delete(); + return redirect()->route('capacidades.index')->with('success', 'Capacidad eliminada exitosamente.'); + } +} diff --git a/app/Models/Capacidad.php b/app/Models/Capacidad.php new file mode 100644 index 0000000..f495253 --- /dev/null +++ b/app/Models/Capacidad.php @@ -0,0 +1,13 @@ +<?php + +namespace App\Models; + +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; + +class Capacidad extends Model +{ + use HasFactory; + protected $table = 'capacidades'; + protected $fillable = ['capacidad']; +} diff --git a/database/factories/CapacidadFactory.php b/database/factories/CapacidadFactory.php new file mode 100644 index 0000000..89e59f8 --- /dev/null +++ b/database/factories/CapacidadFactory.php @@ -0,0 +1,24 @@ +<?php + +namespace Database\Factories; + +use Illuminate\Database\Eloquent\Factories\Factory; + +/** + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Capacidad> + */ +class CapacidadFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array<string, mixed> + */ + public function definition(): array + { + return [ + + // + ]; + } +} diff --git a/database/migrations/2025_03_13_133629_create_capacidads_table.php b/database/migrations/2025_03_13_133629_create_capacidads_table.php new file mode 100644 index 0000000..87eb55b --- /dev/null +++ b/database/migrations/2025_03_13_133629_create_capacidads_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('capacidades', function (Blueprint $table) { + $table->id(); + $table->integer('capacidad')->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('capacidades'); + } +}; diff --git a/database/seeders/CapacidadSeeder.php b/database/seeders/CapacidadSeeder.php new file mode 100644 index 0000000..17537a5 --- /dev/null +++ b/database/seeders/CapacidadSeeder.php @@ -0,0 +1,21 @@ +<?php + +namespace Database\Seeders; + +use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use Illuminate\Database\Seeder; +use App\Models\Capacidad; +class CapacidadSeeder extends Seeder +{ + /** + * Run the database seeds. + */ + public function run(): void + { + Capacidad::create([ + 'capacidad' => 100, + ]); + + // + } +} diff --git a/resources/views/capacidades.blade.php b/resources/views/capacidades.blade.php new file mode 100644 index 0000000..3936eed --- /dev/null +++ b/resources/views/capacidades.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.dashboard') + +@section('content') +<div class="container mx-auto px-4 py-6"> + @if(session('success')) + <div id="success-message" 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 Capacidades</h2> + <a href="{{ route('capacidades.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> + + <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">Cantidad</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($capacidades as $capacidad) + <tr class="hover:bg-gray-50"> + <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $capacidad->id }}</td> + <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $capacidad->cantidad }}</td> + <td class="px-6 py-4 whitespace-nowrap text-sm"> + <div class="flex gap-2"> + <a href="{{ route('capacidades.edit', $capacidad->id) }}" + class="text-blue-600 hover:text-blue-900"> + <i class="fas fa-edit"></i> + </a> + <form action="{{ route('capacidades.destroy', $capacidad->id) }}" + method="POST" + class="inline"> + @csrf + @method('DELETE') + <button type="submit" + 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> +@endsection diff --git a/resources/views/capacidadesCrearEditar.blade.php b/resources/views/capacidadesCrearEditar.blade.php new file mode 100644 index 0000000..aebf05e --- /dev/null +++ b/resources/views/capacidadesCrearEditar.blade.php @@ -0,0 +1,132 @@ +@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($capacidad) ? 'Editar Capacidad' : 'Nueva Capacidad' }} + </h2> + <div class="h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center"> + <i class="fas fa-database 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="capacidadForm" + action="{{ isset($capacidad) ? route('capacidades.update', $capacidad->id) : route('capacidades.store') }}" + method="POST"> + @csrf + @if(isset($capacidad)) + @method('PUT') + @endif + + <div class="space-y-6"> + <!-- Campo Cantidad --> + <div> + <label for="cantidad" class="block text-sm font-medium text-gray-700 mb-2"> + Cantidad + </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-hashtag text-gray-400"></i> + </div> + <input type="number" + name="cantidad" + id="cantidad" + 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($capacidad) ? $capacidad->cantidad : old('cantidad') }}" + placeholder="Ingrese la cantidad" + min="0" + required> + </div> + @error('cantidad') + <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('capacidades.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="submit" + 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($capacidad) ? 'Actualizar' : 'Guardar' }} + </button> + </div> + </div> + </form> + </div> + </div> + </div> +</div> + +<script> +function confirmarAccion() { + const esEdicion = {{ isset($capacidad) ? 'true' : 'false' }}; + const cantidad = document.getElementById('cantidad').value.trim(); + + if (!cantidad) { + Swal.fire({ + title: 'Error', + text: 'La cantidad es obligatoria', + icon: 'error', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Entendido' + }); + return; + } + + Swal.fire({ + title: esEdicion ? '¿Editar capacidad?' : '¿Guardar capacidad?', + html: esEdicion ? + `¿Estás seguro de editar la capacidad a:<br><strong>${cantidad}</strong>?` : + `¿Estás seguro de guardar la capacidad:<br><strong>${cantidad}</strong>?`, + icon: 'question', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: esEdicion ? 'Sí, editar' : 'Sí, guardar', + cancelButtonText: 'Cancelar' + }).then((result) => { + if (result.isConfirmed) { + document.getElementById('capacidadForm').submit(); + } + }); +} + +// Prevenir envío del formulario con Enter +document.getElementById('capacidadForm').addEventListener('keypress', function(e) { + if (e.key === 'Enter') { + e.preventDefault(); + confirmarAccion(); + } +}); + +// Focus en el campo cantidad al cargar la página +document.addEventListener('DOMContentLoaded', function() { + document.getElementById('cantidad').focus(); +}); +</script> +@endsection diff --git a/resources/views/layouts/dashboard.blade.php b/resources/views/layouts/dashboard.blade.php index eed6e09..9ea01e9 100644 --- a/resources/views/layouts/dashboard.blade.php +++ b/resources/views/layouts/dashboard.blade.php @@ -113,8 +113,8 @@ <!-- Capacidad --> <li> - <a href="/configuracion/capacidad" class="nav-item-hover flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-white/10 backdrop-blur-sm"> - <i class="fas fa-users text-white/80"></i> + <a href="{{ route('capacidades.index') }}" class="nav-item-hover flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-white/10 backdrop-blur-sm"> + <i class="fas fa-database text-white/80"></i> <span class="font-light">Capacidad</span> </a> </li> diff --git a/routes/web.php b/routes/web.php index 916dd06..6810a08 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,6 +6,7 @@ use App\Http\Controllers\HomeController; use App\Http\Controllers\MarcaController; use App\Http\Controllers\DocentesController; use App\Http\Controllers\TiposVeiculosController; +use App\Http\Controllers\CapacidadController; /* |-------------------------------------------------------------------------- | Web Routes @@ -26,6 +27,7 @@ Auth::routes(['register'=>true,'reset'=>false]); Route::resource('marca', MarcaController::class); Route::resource('docentes', DocentesController::class); Route::resource('vehiculos', TiposVeiculosController::class); +Route::resource('capacidades', CapacidadController::class); // Rutas protegidas que requieren autenticación