PHP code example of webxscripts / laravel-smsapi-notification-channel

1. Go to this page and download the library: Download webxscripts/laravel-smsapi-notification-channel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webxscripts / laravel-smsapi-notification-channel example snippets


use Illuminate\Notifications\Notification;
use WebXScripts\SmsApiNotification\SmsApiMessage;

class OrderConfirmation extends Notification
{
    public function __construct(private string $orderNumber) {}

    public function via($notifiable): array
    {
        return ['smsapi'];
    }

    public function toSmsApi($notifiable): SmsApiMessage
    {
        return SmsApiMessage::create("Order #{$this->orderNumber} confirmed.")
            ->from('MyShop');
    }
}

SmsApiMessage::create('Code: 123456')
    ->from('MyApp')
    ->encoding('utf-8')
    ->test(app()->environment('testing'))
    ->fast(true)
    ->normalize(true)
    ->single(false)
    ->expirationDate(now()->addMinutes(5))
    ->notifyUrl('https://example.com/sms-delivery')
    ->template('verification_code')
    ->param1($this->code)
    ->param2($notifiable->name);

   public function getSmsApiPhoneNumber(): string
   {
       return $this->phone_number;
   }
   

$user->notify(new OrderConfirmation('ORD-12345'));

Notification::send($users, new OrderConfirmation('ORD-12345'));

Notification::route('smsapi', '+48123456789')
    ->notify(new OrderConfirmation('ORD-12345'));

SmsApiMessage::create('...')
    ->from(string)
    ->encoding(string)
    ->test(bool)
    ->fast(bool)
    ->normalize(bool)
    ->noUnicode(bool)
    ->single(bool)
    ->notifyUrl(string)
    ->expirationDate(DateTimeInterface)
    ->timeRestriction(string)
    ->partnerId(string)
    ->checkIdx(bool)
    ->idx(array)
    ->template(string)
    ->param1(string)
    ->param2(string)
    ->param3(string)
    ->param4(string);

try {
    $user->notify(new OrderConfirmation('ORD-12345'));
} catch (MissingPhoneNumberException $e) {
    Log::warning('User has no phone number');
}
bash
php artisan make:notification OrderConfirmation