diff --git a/app/Http/Controllers/Admin/StaffCardController.php b/app/Http/Controllers/Admin/StaffCardController.php index a80169c..8cbf835 100644 --- a/app/Http/Controllers/Admin/StaffCardController.php +++ b/app/Http/Controllers/Admin/StaffCardController.php @@ -126,10 +126,14 @@ class StaffCardController extends Controller { $staffCard->delete(); - return response()->json([ - 'success' => true, - 'message' => __('Staff card deleted successfully'), - ]); + if (request()->ajax()) { + return response()->json([ + 'success' => true, + 'message' => __('Staff card deleted successfully'), + ]); + } + + return redirect()->route('admin.data-config.staff-cards.index')->with('success', __('Staff card deleted successfully')); } public function toggleStatus(StaffCard $staffCard) diff --git a/app/Models/StaffCardLog.php b/app/Models/StaffCardLog.php index b2cd862..ba404c3 100644 --- a/app/Models/StaffCardLog.php +++ b/app/Models/StaffCardLog.php @@ -30,6 +30,25 @@ class StaffCardLog extends Model 'created_at' => 'datetime', ]; + /** + * 註冊 Model 事件以自動更新 StaffCard 的最後使用狀態 + */ + protected static function booted() + { + static::created(function ($log) { + if ($log->staff_card_id) { + // 使用 withoutGlobalScopes 確保不論在任何 Session Context 下皆能正確寫入 + $staffCard = StaffCard::withoutGlobalScopes()->find($log->staff_card_id); + if ($staffCard) { + $staffCard->update([ + 'last_used_at' => $log->created_at ?? now(), + 'last_machine_id' => $log->machine_id, + ]); + } + } + }); + } + /** * 取得關聯的員工卡片 */ diff --git a/lang/en.json b/lang/en.json index e591b34..834e5c8 100644 --- a/lang/en.json +++ b/lang/en.json @@ -144,6 +144,7 @@ "Are you sure you want to delete this product?": "Are you sure you want to delete this product?", "Are you sure you want to delete this product? All related historical translation data will also be removed.": "Are you sure you want to delete this product? All related historical translation data will also be removed.", "Are you sure you want to delete this role? This action cannot be undone.": "Are you sure you want to delete this role? This action cannot be undone.", + "Are you sure you want to delete this staff card? This action cannot be undone.": "Are you sure you want to delete this staff card? This action cannot be undone.", "Are you sure you want to delete your account?": "Are you sure you want to delete your account?", "Are you sure you want to disable this advertisement?": "Are you sure you want to disable this advertisement?", "Are you sure you want to disable this pass code? It will no longer be valid for machine access.": "Are you sure you want to disable this pass code? It will no longer be valid for machine access.", diff --git a/lang/ja.json b/lang/ja.json index 5d10751..61dd5ba 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -144,6 +144,7 @@ "Are you sure you want to delete this product?": "この商品を削除してもよろしいですか?", "Are you sure you want to delete this product? All related historical translation data will also be removed.": "この商品を削除してもよろしいですか?関連するすべての翻訳履歴データも削除されます。", "Are you sure you want to delete this role? This action cannot be undone.": "このロールを削除してもよろしいですか?取り消しはできません。", + "Are you sure you want to delete this staff card? This action cannot be undone.": "このスタッフカードを削除してもよろしいですか?この操作は取り消せません。", "Are you sure you want to delete your account?": "アカウントを削除してもよろしいですか?", "Are you sure you want to disable this advertisement?": "この広告を無効にしてもよろしいですか?", "Are you sure you want to disable this pass code? It will no longer be valid for machine access.": "このパスコードを無効にしてもよろしいですか?機器へのアクセスに使用できなくなります。", diff --git a/lang/zh_TW.json b/lang/zh_TW.json index ae8d04e..9dadedc 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -144,6 +144,7 @@ "Are you sure you want to delete this product?": "您確定要刪除此商品嗎?", "Are you sure you want to delete this product? All related historical translation data will also be removed.": "確定要刪除此商品嗎?所有相關的歷史翻譯數據也將被移除。", "Are you sure you want to delete this role? This action cannot be undone.": "您確定要刪除此角色嗎?此操作將無法復原。", + "Are you sure you want to delete this staff card? This action cannot be undone.": "您確定要刪除此員工識別卡嗎?此操作將無法復原。", "Are you sure you want to delete your account?": "您確定要刪除您的帳號嗎?", "Are you sure you want to disable this advertisement?": "您確定要停用此廣告嗎?", "Are you sure you want to disable this pass code? It will no longer be valid for machine access.": "您確定要停用此通行碼嗎?停用後將無法再用於機台存取。",