-
app/Notifications/CommentReceivedNotification.php
Open in GitHubuse App\Types\Notification; use Illuminate\Support\Str; use Illuminate\Notifications\Messages\MailMessage; class CommentReceivedNotification extends Notification { public array $payload; public function __construct(array $payload) { $this->payload = $payload; } public function toArray($notifiable) : array { return $this->payload; } public function toMail($notifiable) : MailMessage { return $this->email() ->subject('New Comment - ' . Str::limit($this->payload['title'], 40)) ->markdown('mail.notification.comment', $this->payload); } }
-
app/Actions/Comment/NotifyAction.php
Open in GitHubuse App\Models\Tip; use App\Models\User; use App\Types\Action; use App\Models\Comment; use App\Enums\NotificationType; use App\Actions\Notification\StoreAction; use App\Notifications\CommentReceivedNotification; class NotifyAction extends Action { public static function execute(User $user, Comment | Tip $source, string $message) : void { $tip = $source instanceof Tip ? $source : $source->tip; StoreAction::execute($source->user, $user, $tip, NotificationType::COMMENT, $message); if (! setting($source->user, 'notifications_email_comments')) { return; } $payload = [ 'user' => $user->name, 'title' => $tip->title, 'message' => $message, 'url' => route('tips.show', ['tip' => $tip]), ]; $source->user->notify(new CommentReceivedNotification($payload)); } }