<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jamesmills / laravel-notification-rate-limit example snippets
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Jamesmills\LaravelNotificationRateLimit\RateLimitedNotification;
use Jamesmills\LaravelNotificationRateLimit\ShouldRateLimit;
class NotifyUserOfOrderUpdateNotification extends Notification implements ShouldRateLimit
{
use Queueable;
use RateLimitedNotification;
...
// Do not log skipped notifications
protected $logSkippedNotifications = false;
public function rateLimitCustomCacheKeyParts()
{
return [
$this->account_id
];
}
class User extends Authenticatable
{
use Notifiable;
protected $fillable = ['id', 'name', 'email', 'groupId'];
public function rateLimitNotifiableKey(): string
{
return $this->group_id;
}
}
class Customer extends Authenticatable
{
use Notifiable;
protected $fillable = ['id', 'name', 'email'];
public function rateLimitNotifiableKey(): string
{
return get_class($this) . '#' . $this->id;
}
}
class Agent extends Authenticatable
{
use Notifiable;
protected $fillable = ['id', 'name', 'email'];
public function rateLimitNotifiableKey(): string
{
return get_class($this) . '#' . $this->id;
}
}