From c82173fb15a68bd2ba85a81f0582ea6c1c723c2e Mon Sep 17 00:00:00 2001 From: Abolfazl Esmailinejad Date: Sun, 29 Dec 2019 13:49:47 +0330 Subject: [PATCH 1/2] Add on-demand notifications section --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 640036a..aae0bf4 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,13 @@ class ExampleNotification extends Notification ``` You can also use `->params(["param1" => "val"])` to add extra parameters to the request and `->headers(["header1" => "val"])` to add extra headers to the request. +#### On-Demand Notifications +Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification: +``` +Notification::route(\Gr8Shivam\SmsApi\Notifications\SmsApiChannel::class, 'TO') + ->notify(new ExampleNotification()); +``` + ### Getting Response You can get response by using `->response()` or get the Response Code using `->getResponseCode()`. For example, `smsapi()->sendMessage("TO","MESSAGE")->response();` From f2402651716f67738350cca860e6578c5afe1aae Mon Sep 17 00:00:00 2001 From: Abolfazl Esmailinejad Date: Sun, 29 Dec 2019 13:51:33 +0330 Subject: [PATCH 2/2] Integrate with on-demand notifications and get mobile number by AnonymousNotifiable objects --- src/Notifications/SmsApiChannel.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Notifications/SmsApiChannel.php b/src/Notifications/SmsApiChannel.php index 01ea87c..91e12ab 100644 --- a/src/Notifications/SmsApiChannel.php +++ b/src/Notifications/SmsApiChannel.php @@ -4,6 +4,7 @@ use Gr8Shivam\SmsApi\Notifications\SmsApiMessage; use Gr8Shivam\SmsApi\SmsApi; +use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\Notification; class SmsApiChannel @@ -28,7 +29,13 @@ public function __construct(SmsApi $client) { */ public function send($notifiable, Notification $notification) { - if (! $mobile = $notifiable->routeNotificationFor('sms_api')) { + if ($notifiable instanceof AnonymousNotifiable) { + $mobile = $notifiable->routes[SmsApiChannel::class]; + } else { + $mobile = $notifiable->routeNotificationFor('sms_api'); + } + + if (!$mobile) { return; }