Downloads
Stars
Version
Laravel wrapper for Thai Bulk SMS.
You can install the package via composer:
composer require ibnuhalimm/laravel-thai-bulk-sms
Optionally, you can publish the config file of this package with this command:
php artisan vendor:publish --provider="Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsServiceProvider"
Put your API Key
, Secret Key
, and THAI_BULK_SENDER
to .env
file:
THAI_BULK_API_KEY=
THAI_BULK_SECRET_KEY=
THAI_BULK_SENDER=
You can directly use the ThaiBulkSms
Facade (the alias or class itself):
use Ibnuhalimm\LaravelThaiBulkSms\Facades\ThaiBulkSms;
// Send the sms to single recipient
$phoneNumber = '+6612345678';
$message = 'Hi, our message here.';
ThaiBulkSms::send($phoneNumber, $message);
// Send the sms to multiple phone number
$phoneNumber = [
'+6612345678',
'+6690111213',
];
$message = 'Hi, our message here.';
ThaiBulkSms::send($phoneNumber, $message);
The response format of this method will be like Thai Bulk SMS API's Response.
Notifications
Let's take a look at the implementation as Notifications Channel.
use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsChannel;
use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsMessage;
use Illuminate\Notifications\Notification;
class VerifyMobileNumber extends Notification
{
public function via()
{
return [ThaiBulkSmsChannel::class];
}
public function toThaiBulkSms($notifiable)
{
return (new ThaiBulkSmsMessage())
->message("Your OTP to complete the registration is {$this->otp}");
}
}
In order to let the notification know which mobile phone number are you sending to, by default the channel will look for the mobile_number
attribute of Notifiable model. If you want to override this behaviour, add the routeNotificationForThaiBulkSms
method in your Notifiable model.
public function routeNotificationForThaiBulkSms()
{
return $this->phone;
}
or set the recipient mobile number directly to the notifiable instance using to
method
...
public function toThaiBulkSms($notifiable)
{
return (new ThaiBulkSmsMessage())
->message("Your OTP to complete the registration is {$notifiable->otp}")
->to($notifiable->phone); // add this
}
...
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.