diff --git a/app/Http/Controllers/Admin/RemoteController.php b/app/Http/Controllers/Admin/RemoteController.php
index 9fceafc..60588cc 100644
--- a/app/Http/Controllers/Admin/RemoteController.php
+++ b/app/Http/Controllers/Admin/RemoteController.php
@@ -42,7 +42,10 @@ class RemoteController extends Controller
$machines = $machineQuery->paginate($request->input('per_page', 10), ['*'], 'machine_page');
// --- 2. 歷史紀錄處理 (Operation Records Tab) ---
+ // whereHas('machine') 會套用 Machine 的 machine_access 全域作用域,
+ // 確保租戶僅能看到自己被授權機台的指令紀錄(系統管理員不受作用域限制,仍可看全部)。
$historyQuery = RemoteCommand::where('command_type', '!=', 'reload_stock')
+ ->whereHas('machine')
->with(['machine', 'user']);
if ($request->filled('search') && ($request->input('tab') === 'history' || !$request->has('tab'))) {
@@ -233,8 +236,9 @@ class RemoteController extends Controller
->paginate($request->input('per_page', 10), ['*'], 'machine_page');
// 2. 歷史紀錄查詢與分頁
+ // whereHas('machine') 套用 machine_access 作用域,租戶僅能看到自己授權機台的補貨紀錄。
$historyQuery = RemoteCommand::with(['machine', 'user']);
- $historyQuery->where('command_type', 'reload_stock');
+ $historyQuery->whereHas('machine')->where('command_type', 'reload_stock');
if ($request->filled('search')) {
$search = $request->input('search');
diff --git a/resources/views/admin/remote/partials/tab-history-index.blade.php b/resources/views/admin/remote/partials/tab-history-index.blade.php
index 4823094..20c5ded 100644
--- a/resources/views/admin/remote/partials/tab-history-index.blade.php
+++ b/resources/views/admin/remote/partials/tab-history-index.blade.php
@@ -162,7 +162,7 @@
@foreach ($history as $item)
- | machine->only(['id', 'name', 'serial_no', 'image_urls'])) }})">
+ | machine?->only(['id', 'name', 'serial_no', 'image_urls']) ?? null)) }})">
@@ -295,7 +295,7 @@
@forelse ($history as $item)
machine->only(['id', 'name', 'serial_no', 'image_urls'])) }})">
+ @click="selectMachine({{ Js::from(($item->machine?->only(['id', 'name', 'serial_no', 'image_urls']) ?? null)) }})">
@@ -379,7 +379,7 @@
- |