A Laravel 11+ notification channel for SmsApi with PHP 8.2+ support.
- PHP 8.2 or higher
- Laravel 11 or newer
- SmsApi account and API token
composer require webxscripts/laravel-smsapi-notification-channel
php artisan vendor:publish --tag=smsapi-config
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/
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');
}
}
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);
-
SmsApiNotifiable
interface:public function getSmsApiPhoneNumber(): string { return $this->phone_number; }
-
routeNotificationForSmsApi()
method -
routeNotificationForSms()
method -
Model attributes:
phone
orphone_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);
All methods return an immutable instance.
Custom exceptions provided:
MissingPhoneNumberException
MissingApiTokenException
InvalidNotificationException
Example:
try {
$user->notify(new OrderConfirmation('ORD-12345'));
} catch (MissingPhoneNumberException $e) {
Log::warning('User has no phone number');
}
composer test # Run tests
composer test-coverage # Run with coverage
composer format # Format code
composer analyse # Static analysis
MIT. See LICENSE.md.