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 Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)