Skip to content

Commit 7034861

Browse files
committed
Add all for setImageAttachments
1 parent 934faf2 commit 7034861

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function routeNotificationForOneSignal()
123123
- `button(OneSignalButton $button)`: Allows you to add buttons to the notification (Supported by iOS 8.0 and Android 4.1+ devices. Icon only works for Android).
124124
- `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference).
125125
- `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference).
126-
126+
- `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments).
127127
### Button usage
128128

129129
```php

src/OneSignalMessage.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ public function button(OneSignalButton $button)
162162
return $this;
163163
}
164164

165+
/**
166+
* Set an image to all possible attachment variables.
167+
* @param string $imageUrl
168+
*
169+
* @return $this
170+
*/
171+
public function setImageAttachments($imageUrl){
172+
$this->extraParameters['ios_attachments']['id1'] = $imageUrl;
173+
$this->extraParameters['big_picture'] = $imageUrl;
174+
$this->extraParameters['adm_big_picture'] = $imageUrl;
175+
$this->extraParameters['chrome_big_picture'] = $imageUrl;
176+
177+
return $this;
178+
}
179+
165180
/**
166181
* @return array
167182
*/

tests/MessageTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,14 @@ public function it_can_set_a_button()
108108
$this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text'));
109109
$this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon'));
110110
}
111+
112+
/** @test */
113+
public function it_can_set_a_image(){
114+
$this->message->setImageAttachments('https://url.com/to/image.jpg');
115+
116+
$this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'ios_attachments.id1'));
117+
$this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'big_picture'));
118+
$this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'adm_big_picture'));
119+
$this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'chrome_big_picture'));
120+
}
111121
}

0 commit comments

Comments
 (0)