NotificationsController.php 559 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Auth;
  5. class NotificationsController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. // 获取登录用户的所有通知
  14. $notifications = Auth::user()->notifications()->paginate(20);
  15. // 标记为已读,未读数量清零
  16. Auth::user()->markAsRead();
  17. return view('pages.notifications.index', compact('notifications'));
  18. }
  19. }