Skip to content

notifications

alizeinodin edited this page Sep 11, 2026 · 2 revisions

Notifications

The sms channel is registered automatically.

use Alizeinodin\SmsApi\Notifications\NotificationMessage;
use Illuminate\Notifications\Notification;

class LoginCodeNotification extends Notification
{
    public function __construct(private string $code) {}

    public function via($notifiable): array
    {
        return ['sms']; // or Sms::otpChannels()
    }

    public function toSms($notifiable): NotificationMessage
    {
        return NotificationMessage::create()
            ->template('otp-login', ['CODE' => $this->code])
            ->failover(['smsir', 'kavenegar']);
    }
}
$user->notify(new LoginCodeNotification('12345'));

Clone this wiki locally