diff --git a/README.md b/README.md index f230d30..9def230 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ class AccountApproved extends Notification - `web()`: Sets the platform value to web. - `link()`: Accepts a string value which will lead to URI specified on notification click. - `title('')`: Accepts a string value for the title. +- `subtitle('')`: Accepts a string value for the subtitle (iOS). - `body('')`: Accepts a string value for the body. - `sound('')`: Accepts a string value for the notification sound file. Notice that if you leave blank the default sound value will be `default`. - `icon('')`: Accepts a string value for the icon file. (Android Only) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index f9caef9..42a4f73 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -17,6 +17,11 @@ class PusherMessage */ protected string|null $title = null; + /** + * The message subtitle. + */ + protected string|null $subtitle = null; + /** * The phone number the message should be sent from. */ @@ -195,6 +200,19 @@ public function title(string $value): self return $this; } + /** + * Set the message subtitle. + * + * @param string $value + * @return $this + */ + public function subtitle(string $value): self + { + $this->subtitle = $value; + + return $this; + } + /** * Set the message body. * @@ -306,6 +324,10 @@ public function toiOS(): array ], ]; + if ($this->subtitle) { + $message['apns']['aps']['alert']['subtitle'] = $this->subtitle; + } + $this->formatMessage($message); return $message; diff --git a/tests/MessageTest.php b/tests/MessageTest.php index fe223d0..0ff9ade 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -72,6 +72,14 @@ public function it_can_set_the_title(): void $this->assertEquals('myTitle', Arr::get($this->message->toAndroid(), 'fcm.notification.title')); } + /** @test */ + public function it_can_set_the_subtitle(): void + { + $this->message->subtitle('mySubTitle'); + + $this->assertEquals('mySubTitle', Arr::get($this->message->toiOS(), 'apns.aps.alert.subtitle')); + } + /** @test */ public function it_can_set_the_body(): void {