2022-11-18 09:16:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2022-11-19 06:04:42 +00:00
|
|
|
use App\Exceptions\CommonException;
|
2022-11-18 09:16:30 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2022-11-18 11:55:42 +00:00
|
|
|
use App\Models\WorkOrder\Reply;
|
2022-11-18 10:50:28 +00:00
|
|
|
use App\Models\WorkOrder\WorkOrder;
|
2022-11-18 11:39:30 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2022-11-18 09:16:30 +00:00
|
|
|
use Illuminate\Http\Request;
|
2022-11-18 11:39:30 +00:00
|
|
|
use Illuminate\View\View;
|
2022-11-18 09:16:30 +00:00
|
|
|
|
|
|
|
class WorkOrderController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2022-11-19 11:56:21 +00:00
|
|
|
* @param WorkOrder $workOrder
|
|
|
|
*
|
2022-11-18 11:39:30 +00:00
|
|
|
* @return View
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-18 11:39:30 +00:00
|
|
|
public function index(WorkOrder $workOrder): View
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
2022-11-20 03:58:01 +00:00
|
|
|
$workOrders = $workOrder->with(['user', 'host'])->latest()->paginate(100);
|
2022-11-18 11:39:30 +00:00
|
|
|
return view('admin.work-orders.index', compact('workOrders'));
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
2022-11-19 04:38:26 +00:00
|
|
|
|
2022-11-18 09:16:30 +00:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param WorkOrder $workOrder
|
2022-11-19 04:38:26 +00:00
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @return View
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-18 11:55:42 +00:00
|
|
|
public function show(WorkOrder $workOrder): View
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-18 11:39:30 +00:00
|
|
|
|
2022-11-18 11:55:42 +00:00
|
|
|
$workOrder->load(['user', 'module']);
|
|
|
|
|
2022-11-20 02:56:42 +00:00
|
|
|
$replies = Reply::where('work_order_id', $workOrder->id)->latest()->paginate(100);
|
2022-11-18 11:55:42 +00:00
|
|
|
|
|
|
|
return view('admin.work-orders.show', compact('workOrder', 'replies'));
|
|
|
|
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param WorkOrder $workOrder
|
2022-11-18 11:39:30 +00:00
|
|
|
*
|
|
|
|
* @return View
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-18 11:39:30 +00:00
|
|
|
public function edit(WorkOrder $workOrder): View
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-18 11:39:30 +00:00
|
|
|
|
|
|
|
return view('admin.work-orders.edit', compact('workOrder'));
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param WorkOrder $workOrder
|
2022-11-18 11:39:30 +00:00
|
|
|
*
|
|
|
|
* @return RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-18 11:39:30 +00:00
|
|
|
public function update(Request $request, WorkOrder $workOrder): RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-18 11:39:30 +00:00
|
|
|
|
|
|
|
$request->validate([
|
|
|
|
'title' => 'required|string|max:255',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$workOrder->update($request->all());
|
|
|
|
|
|
|
|
return back()->with('success', '工单更新成功');
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param WorkOrder $workOrder
|
2022-11-19 04:38:26 +00:00
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @return RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-19 03:06:02 +00:00
|
|
|
public function destroy(WorkOrder $workOrder): RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-19 06:04:42 +00:00
|
|
|
try {
|
|
|
|
$workOrder->safeDelete();
|
|
|
|
} catch (CommonException $e) {
|
|
|
|
return back()->with('error', $e->getMessage());
|
|
|
|
}
|
2022-11-19 03:06:02 +00:00
|
|
|
|
|
|
|
return redirect()->route('admin.work-orders.index')->with('success', '正在排队删除工单。');
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
}
|