Browse Source

Status

se hizo el edit para mostrar si un docente esta activo o no en la base de datos
main
TheSilva7 1 week ago
parent
commit
27d8970f20
  1. 29
      app/Http/Controllers/DocentesController.php
  2. 3
      app/Models/Docentes.php
  3. 28
      database/migrations/2025_03_27_054337_add_status_to_docentes_table.php
  4. 26
      resources/views/docentes.blade.php
  5. 1
      routes/web.php

29
app/Http/Controllers/DocentesController.php

@ -19,11 +19,12 @@ class DocentesController extends Controller
if ($busqueda) { if ($busqueda) {
// Busca docentes que coincidan con el término de búsqueda // Busca docentes que coincidan con el término de búsqueda
$docentes = Docentes::where('nombre', 'LIKE', "%{$busqueda}%") $docentes = Docentes::where(function($query) use ($busqueda) {
->orWhere('correo', 'LIKE', "%{$busqueda}%") $query->where('nombre', 'LIKE', "%{$busqueda}%")
->orWhere('tipo_licencia', 'LIKE', "%{$busqueda}%") ->orWhere('correo', 'LIKE', "%{$busqueda}%")
->orWhere('materia', 'LIKE', "%{$busqueda}%") ->orWhere('tipo_licencia', 'LIKE', "%{$busqueda}%")
->get(); ->orWhere('materia', 'LIKE', "%{$busqueda}%");
})->get();
if ($docentes->isEmpty()) { if ($docentes->isEmpty()) {
return redirect()->route('docentes.index') return redirect()->route('docentes.index')
@ -79,7 +80,8 @@ class DocentesController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$docente = Docentes::find($id); $docente = Docentes::find($id);
$docente->update($request->all()); $docente->fill($request->all());
$docente->save();
return redirect()->route('docentes.index')->with('success', 'Docente actualizado correctamente'); return redirect()->route('docentes.index')->with('success', 'Docente actualizado correctamente');
} }
@ -89,8 +91,19 @@ class DocentesController extends Controller
public function destroy($id) public function destroy($id)
{ {
$docente = Docentes::find($id); $docente = Docentes::find($id);
$docente->delete(); $docente->status = false;
return redirect()->route('docentes.index')->with('success', 'Docente eliminado correctamente'); $docente->save();
return redirect()->route('docentes.index')->with('success', 'Docente desactivado correctamente');
}
public function toggleStatus($id)
{
$docente = Docentes::find($id);
$docente->status = !$docente->status;
$docente->save();
$mensaje = $docente->status ? 'Docente activado correctamente' : 'Docente desactivado correctamente';
return redirect()->route('docentes.index')->with('success', $mensaje);
} }
public function export($format) public function export($format)

3
app/Models/Docentes.php

@ -14,6 +14,7 @@ class Docentes extends Model
'telefono', 'telefono',
'correo', 'correo',
'tipo_licencia', 'tipo_licencia',
'materia' 'materia',
'status'
]; ];
} }

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

26
resources/views/docentes.blade.php

@ -82,6 +82,7 @@
<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">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">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">Materia</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> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr> </tr>
</thead> </thead>
@ -97,25 +98,20 @@
<td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->correo }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->correo }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->tipo_licencia }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->tipo_licencia }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->materia }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm">{{ $docente->materia }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {{ $docente->status ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' }}">
{{ $docente->status ? 'Activo' : 'Inactivo' }}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm"> <td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex gap-2"> <div class="flex gap-2">
<a href="#" <a href="{{ route('docentes.edit', $docente->id) }}" class="text-blue-600 hover:text-blue-900">
onclick="confirmarEdicion('{{ route('docentes.edit', $docente->id) }}')"
class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
</a> </a>
<form action="{{ route('docentes.destroy', $docente->id) }}" <a href="{{ route('docentes.toggle-status', $docente->id) }}"
method="POST" class="{{ $docente->status ? 'text-red-600 hover:text-red-900' : 'text-green-600 hover:text-green-900' }}">
class="inline" <i class="fas {{ $docente->status ? 'fa-ban' : 'fa-check' }}"></i>
onsubmit="return false;"> </a>
@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> </div>
</td> </td>
</tr> </tr>

1
routes/web.php

@ -42,6 +42,7 @@ Route::get('marcas/excel', [MarcaController::class, 'exportExcel'])->name('marca
Route::get('marcas/pdf', [MarcaController::class, 'exportPDF'])->name('marcas.pdf'); Route::get('marcas/pdf', [MarcaController::class, 'exportPDF'])->name('marcas.pdf');
Route::get('/docentes/export/{format}', [DocentesController::class, 'export'])->name('docentes.export'); Route::get('/docentes/export/{format}', [DocentesController::class, 'export'])->name('docentes.export');
Route::get('/docentes/{id}/toggle-status', [DocentesController::class, 'toggleStatus'])->name('docentes.toggle-status');
// Rutas protegidas que requieren autenticación // Rutas protegidas que requieren autenticación
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function () {

Loading…
Cancel
Save