Looking to hire Laravel developers? Try LaraJobs

laravel-notification-channels-pushsms-ru maintained by batyukovstudio

Description
PushSMS notifications channel for Laravel
Last update
2025/06/14 11:18 (dev-master)
License
Downloads
223

Comments
comments powered by Disqus

PushSMS notifications channel for Laravel

This package makes it easy to send notifications using pushsms.ru with Laravel.

Contents

Installation

Install this package with Composer:

composer require batyukovstudio/laravel-notification-channels-pushsms-ru

The service provider gets loaded automatically. Or you can do this manually:

// config/app.php
'providers' => [
    ...
    NotificationChannels\PushSMS\PushSmsServiceProvider::class,
],

Setting up the PushSms service

Add your PushSms token to your .env:

// .env
...
PUSHSMS_TOKEN=qwerty123

Usage

You need to replace Notification extend with PushSmsNotification class.

namespace App\Notifications;

use NotificationChannels\PushSMS\Notifications\PushSmsNotification;

class MyNotification extends PushSmsNotification
{
    use Queueable;
    
    // ...
}

PushSmsNotification contains $content variable for your text message and toPushSms method. This method will receive a $notifiable entity and should return an NotificationChannels\PushSMS\ApiActions\PushSmsMessage instance:

// PushSmsNotification
}
use Illuminate\Notifications\Notification;
use NotificationChannels\PushSMS\ApiActions\PushSmsMessage;
use NotificationChannels\PushSMS\Notifications\Interfaces\PushSmsable;

abstract class PushSmsNotification extends Notification implements PushSmsable
{
    protected string $content;

    public function toPushSms($notifiable): PushSmsMessage
    {
        return PushSmsMessage::create()->content($this->content);
    }
}

You can use the channel in your via() method inside the notification:

namespace App\Notifications;

use NotificationChannels\PushSMS\Notifications\PushSmsNotification;
use NotificationChannels\PushSMS\PushSmsChannel;

class MyNotification extends PushSmsNotification
{
    public function via($notifiable)
    {
        return [PushSmsChannel::class];
    }
}

In your notifiable model, make sure to include a routeNotificationForPushsms() method, which returns a phone number or an array of phone numbers.

public function routeNotificationForPushsms()
{
    return $this->phone;
}

Message method

content(): Set a content of the notification message.