diff --git a/app/Http/Controllers/TiposVeiculosController.php b/app/Http/Controllers/TiposVeiculosController.php index 7d018d9..b9b1b2f 100644 --- a/app/Http/Controllers/TiposVeiculosController.php +++ b/app/Http/Controllers/TiposVeiculosController.php @@ -15,7 +15,7 @@ class TiposVeiculosController extends Controller $busqueda = $request->busqueda; if($busqueda) { - $tiposVeiculos = tiposVeiculos::where('nombre', 'LIKE', "%{$busqueda}%")->get(); + $tiposVeiculos = tiposVeiculos::where('nombre', 'LIKE', "%{$busqueda}%")->where('status', true)->get(); if($tiposVeiculos->count() == 0) { return redirect()->route('tiposVeiculos.index') @@ -33,7 +33,7 @@ class TiposVeiculosController extends Controller } // Si no hay búsqueda, mostrar todas las marcas - $tiposVeiculos = tiposVeiculos::all(); + $tiposVeiculos = tiposVeiculos::where('status', true)->get(); return view('vehiculos', ["tiposVeiculos" => $tiposVeiculos]); } @@ -52,6 +52,7 @@ class TiposVeiculosController extends Controller public function store(Request $request) { $tiposVeiculos = new tiposVeiculos($request->all()); + $tiposVeiculos->status = true; $tiposVeiculos->save(); return redirect()->route('vehiculos.index')->with('success', 'Tipo de vehiculo creado exitosamente.'); } @@ -80,17 +81,31 @@ class TiposVeiculosController extends Controller { $tipoVehiculo = tiposVeiculos::find($id); $tipoVehiculo->fill($request->all()); + if ($request->has('status')) { + $tipoVehiculo->status = $request->status; + } $tipoVehiculo->save(); return redirect()->route('vehiculos.index')->with('success', 'Vehículo actualizado exitosamente.'); } + public function toggleStatus($id) + { + $tipoVehiculo = tiposVeiculos::findOrFail($id); + $tipoVehiculo->status = !$tipoVehiculo->status; + $tipoVehiculo->save(); + + $mensaje = $tipoVehiculo->status ? 'Tipo de vehículo activado exitosamente.' : 'Tipo de vehículo desactivado exitosamente.'; + return redirect()->route('vehiculos.index')->with('success', $mensaje); + } + /** * Remove the specified resource from storage. */ public function destroy($id) { $tiposVeiculos = tiposVeiculos::find($id); - $tiposVeiculos->delete(); + $tiposVeiculos->status = false; + $tiposVeiculos->save(); return redirect()->route('vehiculos.index')->with('success', 'Vehiculo eliminado exitosamente.'); } } diff --git a/app/Models/tiposVeiculos.php b/app/Models/tiposVeiculos.php index ae100dc..374d218 100644 --- a/app/Models/tiposVeiculos.php +++ b/app/Models/tiposVeiculos.php @@ -11,5 +11,6 @@ class tiposVeiculos extends Model protected $fillable = [ 'nombre', 'tipo_combustible', + 'status', ]; } diff --git a/database/migrations/2025_03_27_164635_add_status_to_tipos_veiculos_table.php b/database/migrations/2025_03_27_164635_add_status_to_tipos_veiculos_table.php new file mode 100644 index 0000000..8dce0bf --- /dev/null +++ b/database/migrations/2025_03_27_164635_add_status_to_tipos_veiculos_table.php @@ -0,0 +1,28 @@ +boolean('status')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('tipos_veiculos', function (Blueprint $table) { + $table->dropColumn('status'); + }); + } +}; diff --git a/resources/views/vehiculos.blade.php b/resources/views/vehiculos.blade.php index 57a7ab9..87a94e8 100644 --- a/resources/views/vehiculos.blade.php +++ b/resources/views/vehiculos.blade.php @@ -56,6 +56,7 @@ ID Vehículo Tipo de Combustible + Estado Acciones @@ -90,25 +91,34 @@ @endif - -
- + + @if($vehiculo->status) + + + Activo + + @else + + + Inactivo + + @endif + + +
+ -
+ @csrf @method('DELETE') -
+ + +
diff --git a/resources/views/vehiculosCrearEditar.blade.php b/resources/views/vehiculosCrearEditar.blade.php index 352f472..74321a2 100644 --- a/resources/views/vehiculosCrearEditar.blade.php +++ b/resources/views/vehiculosCrearEditar.blade.php @@ -87,6 +87,28 @@ @enderror
+ +
+ +
+ +
+ +
+
+ @error('status') +

{{ $message }}

+ @enderror +
+
true,'reset'=>false]); Route::resource('marca', MarcaController::class); Route::resource('docentes', DocentesController::class); Route::resource('vehiculos', TiposVeiculosController::class); +Route::get('/vehiculos/{id}/toggle-status', [TiposVeiculosController::class, 'toggleStatus'])->name('vehiculos.toggle-status'); Route::resource('tiposLicencias', TiposLicenciasController::class);