- Rename IsCommenter trait to CanComment, Commenter interface to Commentator - Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription) - Rename user_type/user_id polymorphic columns to commenter_type/commenter_id - Rename Config class to CommentsConfig, update config key tables->table_names - Rename getCommentName() to getCommentDisplayName() on commentator models - Add column_names config section for commenter morph customization - Add table_names config with all 5 tables individually configurable - Expand translation file with structured i18n groups - Update all Blade views, Livewire components, events, listeners, and tests
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Relaticle\Comments\Notifications;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Str;
|
|
use Relaticle\Comments\CommentsConfig;
|
|
use Relaticle\Comments\Models\Comment;
|
|
|
|
class UserMentionedNotification extends Notification
|
|
{
|
|
public function __construct(
|
|
public readonly Comment $comment,
|
|
public readonly Model $mentionedBy,
|
|
) {}
|
|
|
|
/** @return array<int, string> */
|
|
public function via(mixed $notifiable): array
|
|
{
|
|
return CommentsConfig::getNotificationChannels();
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function toDatabase(mixed $notifiable): array
|
|
{
|
|
return [
|
|
'comment_id' => $this->comment->id,
|
|
'commentable_type' => $this->comment->commentable_type,
|
|
'commentable_id' => $this->comment->commentable_id,
|
|
'mentioner_name' => $this->mentionedBy->getCommentDisplayName(),
|
|
'body' => Str::limit(strip_tags($this->comment->body), 100),
|
|
];
|
|
}
|
|
|
|
public function toMail(mixed $notifiable): MailMessage
|
|
{
|
|
$mentionerName = $this->mentionedBy->getCommentDisplayName();
|
|
|
|
return (new MailMessage)
|
|
->subject('You were mentioned in a comment')
|
|
->line("{$mentionerName} mentioned you in a comment:")
|
|
->line(Str::limit(strip_tags($this->comment->body), 200));
|
|
}
|
|
}
|