Browse Source

Estatus 2

main
TheSilva7 6 days ago
parent
commit
ce184c6548
  1. 21
      app/Http/Controllers/TiposVeiculosController.php
  2. 1
      app/Models/tiposVeiculos.php
  3. 28
      database/migrations/2025_03_27_164635_add_status_to_tipos_veiculos_table.php
  4. 34
      resources/views/vehiculos.blade.php
  5. 22
      resources/views/vehiculosCrearEditar.blade.php
  6. 1
      routes/web.php

21
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.');
}
}

1
app/Models/tiposVeiculos.php

@ -11,5 +11,6 @@ class tiposVeiculos extends Model
protected $fillable = [
'nombre',
'tipo_combustible',
'status',
];
}

28
database/migrations/2025_03_27_164635_add_status_to_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::table('tipos_veiculos', function (Blueprint $table) {
$table->boolean('status')->default(true);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('tipos_veiculos', function (Blueprint $table) {
$table->dropColumn('status');
});
}
};

34
resources/views/vehiculos.blade.php

@ -56,6 +56,7 @@
<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">Tipo de Combustible</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Estado</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
@ -90,25 +91,34 @@
</span>
@endif
</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">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
@if($vehiculo->status)
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
<i class="fas fa-check-circle mr-1"></i>
Activo
</span>
@else
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
<i class="fas fa-times-circle mr-1"></i>
Inactivo
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex space-x-2">
<a href="{{ 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;">
<form action="{{ route('vehiculos.destroy', $vehiculo->id) }}" method="POST" class="inline">
@csrf
@method('DELETE')
<button type="button"
onclick="confirmarEliminacion(this)"
class="text-red-600 hover:text-red-900">
<button type="submit" class="text-red-600 hover:text-red-900" onclick="return confirm('¿Estás seguro de que deseas eliminar este vehículo?')">
<i class="fas fa-trash"></i>
</button>
</form>
<a href="{{ route('vehiculos.toggle-status', $vehiculo->id) }}" class="text-yellow-600 hover:text-yellow-900">
<i class="fas fa-power-off"></i>
</a>
</div>
</td>
</tr>

22
resources/views/vehiculosCrearEditar.blade.php

@ -87,6 +87,28 @@
@enderror
</div>
<!-- Campo Estado -->
<div>
<label for="status" class="block text-sm font-medium text-gray-700 mb-2">
Estado
</label>
<div class="relative rounded-md shadow-sm">
<select name="status"
id="status"
class="block w-full pl-3 pr-10 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
required>
<option value="1" {{ isset($tipoVehiculo) && $tipoVehiculo->status ? 'selected' : '' }}>Activo</option>
<option value="0" {{ isset($tipoVehiculo) && !$tipoVehiculo->status ? 'selected' : '' }}>Inactivo</option>
</select>
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
<i class="fas fa-power-off text-gray-400"></i>
</div>
</div>
@error('status')
<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') }}"

1
routes/web.php

@ -32,6 +32,7 @@ Auth::routes(['register'=>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);

Loading…
Cancel
Save