70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Models\Fault;
|
||
|
|
||
|
class FaultController extends Controller
|
||
|
{
|
||
|
public function index()
|
||
|
{
|
||
|
$faults = Fault::all();
|
||
|
$test = 'hola que tal?';
|
||
|
$colors = [
|
||
|
'open' => '#8cf5a8',
|
||
|
'in_progress' => '#f3f58c',
|
||
|
'resolved' => '#8cdaf5',
|
||
|
];
|
||
|
$modalData = session('modalData', null);
|
||
|
$isModalOpen = session('isModalOpen', false);
|
||
|
$updateStatus = session('updateStatus', false);
|
||
|
|
||
|
return view('dashboard.faults', compact('faults', 'test', 'modalData', 'isModalOpen','updateStatus', 'colors'));
|
||
|
}
|
||
|
|
||
|
public function openModal($id)
|
||
|
{
|
||
|
// Obtener los datos de la avería desde la base de datos
|
||
|
$fault = Fault::find($id);
|
||
|
|
||
|
// Guardar el estado del modal y la información en la sesión
|
||
|
session([
|
||
|
'modalData' => $fault,
|
||
|
'isModalOpen' => true
|
||
|
]);
|
||
|
|
||
|
return redirect()->route('dashboard.faults');
|
||
|
}
|
||
|
|
||
|
public function closeModal()
|
||
|
{
|
||
|
// Cerrar el modal al limpiar la sesión
|
||
|
session([
|
||
|
'isModalOpen' => false,
|
||
|
'modalData' => null
|
||
|
]);
|
||
|
|
||
|
return redirect()->route('dashboard.faults');
|
||
|
}
|
||
|
|
||
|
public function updateStatus(Request $request, $id)
|
||
|
{
|
||
|
// Validar los datos del formulario
|
||
|
$request->validate([
|
||
|
'status' => 'required|in:open,in_progress,resolved'
|
||
|
]);
|
||
|
|
||
|
|
||
|
$fault = Fault::find($id);
|
||
|
$fault->status = $request->status;
|
||
|
$fault->save();
|
||
|
$this->closeModal();
|
||
|
|
||
|
return redirect()->route('dashboard.faults');
|
||
|
}
|
||
|
}
|