如何将通知与Laravel通知分组?

如何将通知与Laravel通知分组?,laravel,laravel-notification,Laravel,Laravel Notification,我有一个关于使用Laravel通知的问题,我想调用一个分组通知,而不是重复多次相同的通知 例如,在电子邮件捕获中,如果项目名称及其翻译不存在,Laravel会注册数据,并在向我发送通知时注册。我不想重复这个主题,只制作了一个计数器,消息是这样呈现给我的 我正在占用事件和听众,但我无法在视图中对它们进行分组 控制器 $trans = TranslateProject::create($request->all()); event(new TranslateEven

我有一个关于使用Laravel通知的问题,我想调用一个分组通知,而不是重复多次相同的通知

例如,在电子邮件捕获中,如果项目名称及其翻译不存在,Laravel会注册数据,并在向我发送通知时注册。我不想重复这个主题,只制作了一个计数器,消息是这样呈现给我的

我正在占用事件和听众,但我无法在视图中对它们进行分组

控制器

    $trans = TranslateProject::create($request->all());
    
    event(new TranslateEvent($trans));
    return response()->json(null,200);

class TranslateListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        User::withRole('admin')
            ->each(function(User $user) use ($event){
                Notification::send($user, new TranslateNotification($event->translate));
            });
    }
}
    public static function groopNotification(){
        $amount = 0;
        foreach (Auth::user()->unreadNotifications as $notification) {
            if ($notification->data['id'] == 'Traduccion') {
                $amount++;
            }
        }
        return $amount;
    }
事件

class TranslateEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $translate;
    
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($translate)
    {
        $this->translate = $translate;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
通知

class TranslateNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(TranslateProject $translate)
    {
        $this->translate = $translate;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'uuid'      => $this->translate->id,
            'id'        => 'Traduccion',
            'name'      => $this->translate->translate,
            'route'     => route('translate.index'),
            'created_at'=> Carbon::parse($this->translate->created_at)->diffForHumans()
        ];
    }
}

听众

    $trans = TranslateProject::create($request->all());
    
    event(new TranslateEvent($trans));
    return response()->json(null,200);

class TranslateListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        User::withRole('admin')
            ->each(function(User $user) use ($event){
                Notification::send($user, new TranslateNotification($event->translate));
            });
    }
}
    public static function groopNotification(){
        $amount = 0;
        foreach (Auth::user()->unreadNotifications as $notification) {
            if ($notification->data['id'] == 'Traduccion') {
                $amount++;
            }
        }
        return $amount;
    }
用户

    $trans = TranslateProject::create($request->all());
    
    event(new TranslateEvent($trans));
    return response()->json(null,200);

class TranslateListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        User::withRole('admin')
            ->each(function(User $user) use ($event){
                Notification::send($user, new TranslateNotification($event->translate));
            });
    }
}
    public static function groopNotification(){
        $amount = 0;
        foreach (Auth::user()->unreadNotifications as $notification) {
            if ($notification->data['id'] == 'Traduccion') {
                $amount++;
            }
        }
        return $amount;
    }
HTML

                           @foreach (Auth::user()->unreadNotifications()->take(4)->get() as $notification)

                           @if( $notification->data['id'] == 'Traduccion')
                           <a href="{{ $notification->data['route']}}" class="iq-sub-card">
                              <div class="media align-items-center">
                                 <div class="media-body ml-3">
                                    <h6 class="mb-0 ">There are {{ \App\User::groopNotification() }} translations without projects.</h6>
                                    <small
                                       class="float-right font-size-12">{{ $notification->created_at->diffForHumans() }}</small>
                                 </div>
                              </div>
                           </a>
                           @else

                           @endif
                           @endforeach
@foreach(Auth::user()->unreadNotifications()->将(4)->get()作为$notification)
@如果($notification->data['id']=='Traduccion')
@否则
@恩迪夫
@endforeach