Notifications.php 901 字节
<?php

namespace App\Admin\Extensions\Nav;

use App\Models\System\Notification;
use App\Transformers\System\NotificationTransformer;
use App\Admin\Rewrite\Facades\Admin;

class Notifications
{
    public function __toString()
    {
        $user_ids = [];
        // 获取全部未读的消息
        $un_read = Notification::whereIn('notifiable_id', $user_ids)->whereNull('read_at')->count(['id']);

        $transform = new NotificationTransformer();
        // 获取当登录用户的全部通知
        $notifications =  Notification::whereIn('notifiable_id', $user_ids)->whereNull('read_at')->latest()->take(5)->get();
        $notifications = $notifications->map(function ($notification) use ($transform) {
            return $notification = $transform->transform($notification);
        });
        return view('admin.notifications', compact('un_read', 'notifications'))->render();
    }
}