webxscripts / laravel-smsapi-notification-channel
Modern Laravel Notification Channel for SmsApi PHP Client
1.0.0
2025-07-02 01:29 UTC
Requires
- php: ^8.2
- illuminate/notifications: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- smsapi/php-client: ^3.0
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0|^11.0
README
A Laravel 11+ notification channel for SmsApi with PHP 8.2+ support.
Requirements
- PHP 8.2 or higher
- Laravel 11 or newer
- SmsApi account and API token
Installation
composer require webxscripts/laravel-smsapi-notification-channel php artisan vendor:publish --tag=smsapi-config
Configuration
Add the following to your .env
file:
SMSAPI_TOKEN=your_api_token_here SMSAPI_SERVICE=com SMSAPI_FROM=YourApp
Supported services:
com
(default)pl
- For other regions, use:
SMSAPI_URI=https://api.smsapi.se/
Basic Usage
Create a notification:
php artisan make:notification OrderConfirmation
Example implementation:
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'); } }
Advanced Example
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);
Phone Number Resolution Order
-
SmsApiNotifiable
interface:public function getSmsApiPhoneNumber(): string { return $this->phone_number; }
-
routeNotificationForSmsApi()
method -
routeNotificationForSms()
method -
Model attributes:
phone
orphone_number
Sending Notifications
$user->notify(new OrderConfirmation('ORD-12345')); Notification::send($users, new OrderConfirmation('ORD-12345')); Notification::route('smsapi', '+48123456789') ->notify(new OrderConfirmation('ORD-12345'));
Available Message Methods
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);
All methods return an immutable instance.
Error Handling
Custom exceptions provided:
MissingPhoneNumberException
MissingApiTokenException
InvalidNotificationException
Example:
try { $user->notify(new OrderConfirmation('ORD-12345')); } catch (MissingPhoneNumberException $e) { Log::warning('User has no phone number'); }
Testing & Code Quality
composer test # Run tests composer test-coverage # Run with coverage composer format # Format code composer analyse # Static analysis
License
MIT. See LICENSE.md.