diff --git a/app/Http/Controllers/Admin/WorkOrderController.php b/app/Http/Controllers/Admin/WorkOrderController.php index 1bdf3ed..c4c0352 100644 --- a/app/Http/Controllers/Admin/WorkOrderController.php +++ b/app/Http/Controllers/Admin/WorkOrderController.php @@ -21,7 +21,7 @@ class WorkOrderController extends Controller */ public function index(WorkOrder $workOrder): View { - $workOrders = $workOrder->with(['user', 'host'])->latest()->paginate(20)->withQueryString(); + $workOrders = $workOrder->with(['user', 'host', 'module'])->latest()->paginate(20)->withQueryString(); return view('admin.work-orders.index', compact('workOrders')); } @@ -35,7 +35,7 @@ public function index(WorkOrder $workOrder): View */ public function show(WorkOrder $workOrder): View { - $workOrder->load(['user', 'module']); + $workOrder->load(['user', 'module', 'host']); $replies = (new Reply)->where('work_order_id', $workOrder->id)->latest()->paginate(100); diff --git a/app/Models/WorkOrder/Reply.php b/app/Models/WorkOrder/Reply.php index 0d62573..602bf8c 100644 --- a/app/Models/WorkOrder/Reply.php +++ b/app/Models/WorkOrder/Reply.php @@ -26,6 +26,10 @@ class Reply extends Model 'role' ]; + protected $hidden = [ + 'ip', + ]; + protected static function boot() { parent::boot(); @@ -64,8 +68,9 @@ protected static function boot() $model->role = 'guest'; } - $model->workOrder->save(); + + $model->ip = request()->ip(); }); static::created(function (self $model) { diff --git a/app/Models/WorkOrder/WorkOrder.php b/app/Models/WorkOrder/WorkOrder.php index d49effe..176e7ab 100644 --- a/app/Models/WorkOrder/WorkOrder.php +++ b/app/Models/WorkOrder/WorkOrder.php @@ -31,6 +31,10 @@ class WorkOrder extends Model 'notify' ]; + protected $hidden = [ + 'ip', + ]; + protected $casts = [ 'notify' => 'boolean' ]; @@ -73,6 +77,8 @@ protected static function boot() } $model->notify = true; + + $model->ip = request()->ip(); }); // updated diff --git a/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php b/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php new file mode 100644 index 0000000..87ebbad --- /dev/null +++ b/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php @@ -0,0 +1,32 @@ +string('ip')->nullable()->after('status'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('work_orders', function (Blueprint $table) { + $table->dropColumn('ip'); + }); + } +}; diff --git a/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php b/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php new file mode 100644 index 0000000..d8b3ed8 --- /dev/null +++ b/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php @@ -0,0 +1,32 @@ +string('ip')->nullable()->after('content'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('work_order_replies', function (Blueprint $table) { + $table->dropColumn('ip'); + }); + } +}; diff --git a/resources/views/admin/work-orders/show.blade.php b/resources/views/admin/work-orders/show.blade.php index 40495d5..1204a22 100644 --- a/resources/views/admin/work-orders/show.blade.php +++ b/resources/views/admin/work-orders/show.blade.php @@ -7,7 +7,21 @@ 编辑此工单 用户: {{ $workOrder->user->name }} -
@parsedown($workOrder->content)
+ @if($workOrder->ip) +

IP 地址: {{ $workOrder->ip }}

+ @endif + + @if($workOrder->host_id) + 主机: {{ $workOrder->host->name }} + @endif + + @if($workOrder->module_id) + 模块: {{ $workOrder->module->name }} + @endif + +
+

@parsedown($workOrder->content)

+
@@ -35,6 +49,7 @@ {{ $reply->name }} @endif + @if($reply->is_pending) 投递中 @@ -48,6 +63,14 @@
@parsedown($reply->content)
+ + @if($reply->ip) + + + @endif + @endforeach