Skip to content

[6.x] Replace announcements with control panel notifications - #19541

Merged
brandonkelly merged 5 commits into
6.xfrom
rias/cms-2381-replace-announcements-with-laravel-database-notifications
Sep 2, 2026
Merged

brandonkelly merged 5 commits into
6.xfrom
rias/cms-2381-replace-announcements-with-laravel-database-notifications

Conversation

@riasvdv

@riasvdv riasvdv commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Replaces the core announcements system with Laravel database notifications and adds a control panel notification center.

Control panel notification popover with Workbench seeded notifications

Example

Below is an example of a notification that could extend CpNotification to send to both the email channel and the control panel notifications:

<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\Comment;
use CraftCms\Cms\Cp\Data\NotificationButtonData;
use CraftCms\Cms\Cp\Enums\ButtonVariant;
use CraftCms\Cms\Cp\Notifications\CpNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Channels\MailChannel;
use Illuminate\Notifications\Messages\MailMessage;

class MentionNotification extends CpNotification
{
    public function __construct(
        public readonly Comment $comment,
    ) {
        $url = route('comments.show', $comment);

        parent::__construct(sprintf(
            '**%s** mentioned you in “%s”.',
            $comment->author->name,
            $comment->commentable->title,
        ));

        $this
            ->title('New mention')
            ->byline($comment->author->name)
            ->image(url: $comment->author->avatarUrl, alt: $comment->author->name)
            ->url($url)
            ->buttons([
                new NotificationButtonData(
                    label: 'View comment',
                    url: $url,
                    variant: ButtonVariant::Primary,
                ),
            ]);
    }

    /** @return class-string[] */
    public function via(object $notifiable): array
    {
        return [
            ...parent::via($notifiable),
            MailChannel::class,
        ];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return new MailMessage()
            ->subject("{$this->comment->author->name} mentioned you")
            ->greeting("Hi {$notifiable->name},")
            ->line("{$this->comment->author->name} mentioned you in “{$this->comment->commentable->title}”.")
            ->action('View comment', route('comments.show', $this->comment));
    }
}

Sending the notification is then straightforward:

Notification::send(
    $comment->mentionedUsers,
    new MentionNotification($comment),
);

@linear-code

linear-code Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

CMS-2381

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

@riasvdv
riasvdv marked this pull request as ready for review September 2, 2026 18:58
@brandonkelly
brandonkelly merged commit 35797b9 into 6.x Sep 2, 2026
33 of 34 checks passed
@brandonkelly
brandonkelly deleted the rias/cms-2381-replace-announcements-with-laravel-database-notifications branch September 2, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants