DEV Community

Sesha
Sesha

Posted on

2 2

Add Snooze functionality to Notification channels.

The simple way to add snooze functionality to your notification channels in your Laravel application.


use Carbon\Carbon;

class SnoozeData
{
    public Carbon $snooze_until;

    public function __construct(
        public int $duration,
        public string $type,
    ) {
        $this->getSnoozeUntilTime();
    }

    private function getSnoozeUntilTime(): void
    {
        $time = Carbon::now();

        $this->snooze_until = match ($this->type) {
            'minutes' => $time->addMinutes($this->duration),
            'hours' => $time->addHours($this->duration),
            'days' => $time->addDays($this->duration),
            'weeks' => $time->addWeeks($this->duration),
            default => $time,
        };
    }
}

Enter fullscreen mode Exit fullscreen mode
$details = new SnoozeData(...Request::validate([
   'duration' => ['required', 'integer', 'between:0,1000'],
   'type' => ['required', 'string'],
]));


$notifyUser->update([
  'snooze_until' => $details->snooze_until,
]);


Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up