NotificationController.php 740 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\JsonResponse;
  5. use Illuminate\Support\Facades\Session;
  6. class NotificationController extends Controller
  7. {
  8. /**
  9. * 检查是否有新的通知
  10. */
  11. public function checkNotifications(Request $request): JsonResponse
  12. {
  13. $notification = Session::get('notification');
  14. if ($notification) {
  15. // 清除session中的通知,避免重复显示
  16. Session::forget('notification');
  17. return response()->json([
  18. 'hasNotification' => true,
  19. 'notification' => $notification
  20. ]);
  21. }
  22. return response()->json(['hasNotification' => false]);
  23. }
  24. }