增加 工单 IP 地址

This commit is contained in:
iVampireSP.com 2023-01-14 20:15:04 +08:00
parent f68d44fef6
commit 2f0d0c8cff
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
6 changed files with 102 additions and 4 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('work_orders', function (Blueprint $table) {
$table->string('ip')->nullable()->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('work_orders', function (Blueprint $table) {
$table->dropColumn('ip');
});
}
};

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('work_order_replies', function (Blueprint $table) {
$table->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');
});
}
};

View File

@ -7,7 +7,21 @@
<a href="{{ route('admin.work-orders.edit', $workOrder) }}">编辑此工单</a>
<a href="{{ route('admin.users.edit', $workOrder->user_id) }}">用户: {{ $workOrder->user->name }}</a>
<h5>@parsedown($workOrder->content)</h5>
@if($workOrder->ip)
<p>IP 地址: {{ $workOrder->ip }}</p>
@endif
@if($workOrder->host_id)
<a href="{{ route('admin.hosts.edit', $workOrder->host_id) }}">主机: {{ $workOrder->host->name }}</a>
@endif
@if($workOrder->module_id)
<a href="{{ route('admin.modules.show', $workOrder->module_id) }}">模块: {{ $workOrder->module->name }}</a>
@endif
<hr/>
<p>@parsedown($workOrder->content)</p>
<hr/>
<x-work-order-status :status="$workOrder->status"></x-work-order-status>
@ -35,6 +49,7 @@
{{ $reply->name }}
@endif
<span class="text-end">
@if($reply->is_pending)
<span class="badge bg-primary">投递中</span>
@ -48,6 +63,14 @@
<div class="card-body">
@parsedown($reply->content)
</div>
@if($reply->ip)
<div class="card-footer">
<span>IP 地址: {{ $reply->ip }}</span>
</div>
@endif
</div>
@endforeach