You can install this package via composer:
composer require husnet/laravel-smsupchAdd your SmsUp API key to your config/services.php file:
return [
...
...
'smsUpCh' => [
'token' => env('SMSUPCH_TOKEN'),
'simulate' => env('SMSUPCH_SIMULATE'), // true or false
'sender' => env('SMSUPCH_SENDER_NAME', config('app.name')),
]
...
];Set simulate to true if you want to simulate submitting messages, it's perfect for testing and debugging, it has no cost.
Use artisan to create a notification:
php artisan make:notification someNotificationReturn [smsUpCh] in the public function via($notifiable) method of your notification:
public function via($notifiable)
{
return ['smsUpCh'];
}Add the method public function toSmsUp($notifiable) to your notification, and return an instance of SmsUpChMessage:
use Husnet\LaravelSmsUpCh\SmsUpChMessage;
...
public function toSmsUpCh($notifiable)
{
$message = new SmsUpChMessage();
$message->text($this->text);
return $message;
}If you don't indicate the parameter to, make sure your notifiable entity has routeNotificationForSmsUpCh method defined:
/**
* Route notifications for the SmsUp channel.
*
* @return string
*/
public function routeNotificationForSmsUpCh(): string
{
return $this->phone;
}use Husnet\LaravelSmsUpCh\SmsUpChMessage;
use Husnet\LaravelSmsUpCh\Facades\SmsUpCh;
...
try {
$phone_owner->notify(new ClientNotification($message_text));
}
catch (\Exception $e) {
session()->flash('error', __('Error: SMS API Timeout'));
}LaravelSmsUp comes with handy events which provides the required information about the SMS messages.
Triggered when one or more messages are sent.
Example:
use Husnet\LaravelSmsUpCh\Events\SmsUpChMessageWasSent;
class SmsUpMessageSentListener
{
/**
* Handle the event.
*
* @param SmsUpChMessageWasSent $event
* @return void
*/
public function handle(SmsUpChMessageWasSent $event)
{
$response = $event->response; // Class SmsUpResponse
$message = $event->message; // Class SmsUpMessage
// flashing to session
session()->flash('message.to', $message->getTo());
session()->flash('message.text', $message->getText());
session()->flash('response.status', $response->getStatus());
session()->flash('response.message', $response->getMessage());
session()->flash('response.credits', $response->getCredits());
session()->flash('response.invalid', $response->getInvalid());
}
}In your EventServiceProvider:
protected $listen = [
...
'Husnet\LaravelSmsUpCh\Events\SmsUpChMessageWasSent' => [
'App\Listeners\SmsUpChMessageSentListener',
],
];Visit SmsUp.ch API Documentation for more information.
Feel free to post your issues in the issues section.
The MIT License (MIT). Please see License File for more information.