Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

caneara/tipsea

13 stars
2 code files
View caneara/tipsea on GitHub

app/Notifications/CommentReceivedNotification.php

Open in GitHub
use 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 GitHub
use 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));
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.