├── .editorconfig ├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Exceptions └── CouldNotSendNotification.php ├── FcmChannel.php ├── FcmMessage.php ├── FcmNotification.php └── FcmServiceProvider.php /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes will be documented in this file 4 | 5 | ## 1.0.0 - 201X-XX-XX 6 | 7 | - initial release 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) Chris Bautista 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Package Moved 2 | This package has moved to the Laravel notification channels project. This repository will no longer be maintained. To switch, please see the "Migrating" section below. 3 | 4 | https://github.com/laravel-notification-channels/fcm 5 | 6 | ### Migrating 7 | There are no breaking changes. The namespace will remain the same, so you only need to update your `composer.json` to reference the new package name, and bump the version to `1.6` (which has no breaking changes). 8 | 9 | Switch the old package `require` from: 10 | ```json 11 | "require": { 12 | "coreproc/laravel-notification-channel-fcm": "^1.5" 13 | }, 14 | ``` 15 | 16 | to the new package name: 17 | ```json 18 | "require": { 19 | "laravel-notification-channels/fcm": "^1.6" 20 | }, 21 | ``` 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coreproc/laravel-notification-channel-fcm", 3 | "description": "FCM (Firebase Cloud Messaging) Notifications Driver for Laravel", 4 | "homepage": "https://github.com/CoreProc/fcm", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Chris Bautista", 9 | "email": "chrisbjr@gmail.com", 10 | "homepage": "https://www.coreproc.com", 11 | "role": "Developer" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.6.4", 16 | "guzzlehttp/guzzle": "^6.2", 17 | "illuminate/notifications": "^5.3|^5.4|^5.5|^5.6|^5.7|^5.8|^6.0", 18 | "illuminate/support": "^5.1|^5.2|^5.3|^5.4|^5.5|^5.6|^5.7|^5.8|^6.0" 19 | }, 20 | "require-dev": { 21 | "mockery/mockery": "^0.9.5", 22 | "phpunit/phpunit": "5.*" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "NotificationChannels\\Fcm\\": "src" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "NotificationChannels\\Fcm\\Test\\": "tests" 32 | } 33 | }, 34 | "extra": { 35 | "laravel": { 36 | "providers": [ 37 | "NotificationChannels\\Fcm\\FcmServiceProvider" 38 | ] 39 | } 40 | }, 41 | "scripts": { 42 | "test": "vendor/bin/phpunit" 43 | }, 44 | "config": { 45 | "sort-packages": true 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Exceptions/CouldNotSendNotification.php: -------------------------------------------------------------------------------- 1 | getMessage()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/FcmChannel.php: -------------------------------------------------------------------------------- 1 | client = $client; 23 | } 24 | 25 | /** 26 | * Send the given notification. 27 | * 28 | * @param mixed $notifiable 29 | * @param \Illuminate\Notifications\Notification $notification 30 | * 31 | * @throws \NotificationChannels\Fcm\Exceptions\CouldNotSendNotification 32 | */ 33 | public function send($notifiable, Notification $notification) 34 | { 35 | // Get the token/s from the model 36 | if (! $notifiable->routeNotificationFor('fcm')) { 37 | return; 38 | } 39 | $tokens = (array) $notifiable->routeNotificationFor('fcm'); 40 | 41 | if (empty($tokens)) { 42 | return; 43 | } 44 | 45 | // Get the message from the notification class 46 | $fcmMessage = $notification->toFcm($notifiable); 47 | 48 | if (empty($fcmMessage)) { 49 | return; 50 | } 51 | 52 | if (count($tokens) == 1) { 53 | // Do not use multicast if there is only one recipient 54 | $fcmMessage->setTo($tokens[0]); 55 | $this->sendToFcm($fcmMessage); 56 | } else { 57 | // Use multicast because there are multiple recipients 58 | $partialTokens = array_chunk($tokens, self::MAX_TOKEN_PER_REQUEST, false); 59 | foreach ($partialTokens as $tokens) { 60 | $fcmMessage->setRegistrationIds($tokens); 61 | $this->sendToFcm($fcmMessage); 62 | } 63 | } 64 | } 65 | 66 | protected function sendToFcm($fcmMessage) 67 | { 68 | try { 69 | $this->client->request('POST', '/fcm/send', [ 70 | 'headers' => $this->getClientHeaders($fcmMessage), 71 | 'body' => $fcmMessage->toJson(), 72 | ]); 73 | } catch (RequestException $requestException) { 74 | throw CouldNotSendNotification::serviceRespondedWithAnError($requestException); 75 | } 76 | } 77 | 78 | /** 79 | * This is used to get the headers for the FCM request. We can add customization to the headers here. 80 | * 81 | * @param FcmMessage $fcmMessage 82 | * @return array 83 | */ 84 | protected function getClientHeaders(FcmMessage $fcmMessage) 85 | { 86 | $headers = [ 87 | 'Authorization' => sprintf('key=%s', config('broadcasting.connections.fcm.key')), 88 | 'Content-Type' => 'application/json', 89 | ]; 90 | 91 | // Override the FCM key from the config 92 | if (! empty($fcmMessage->getFcmKey())) { 93 | $headers['Authorization'] = sprintf('key=%s', $fcmMessage->getFcmKey()); 94 | } 95 | 96 | return $headers; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/FcmMessage.php: -------------------------------------------------------------------------------- 1 | fcmKey; 82 | } 83 | 84 | /** 85 | * This method can be used to override the default FCM key used in the config/broadcasting.php. 86 | * 87 | * @param string $fcmKey 88 | * @return $this 89 | */ 90 | public function setFcmKey($fcmKey) 91 | { 92 | $this->fcmKey = $fcmKey; 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * @return string 99 | */ 100 | public function getTo() 101 | { 102 | return $this->to; 103 | } 104 | 105 | /** 106 | * This parameter specifies the recipient of a message. 107 | * The value can be a device's registration token, a device group's notification key, or a single topic (prefixed with /topics/). To send to multiple 108 | * topics, use the condition parameter. 109 | * 110 | * @param string $to 111 | * @return $this 112 | */ 113 | public function setTo($to) 114 | { 115 | $this->to = $to; 116 | 117 | return $this; 118 | } 119 | 120 | /** 121 | * @return array 122 | */ 123 | public function getRegistrationIds() 124 | { 125 | return $this->registrationIds; 126 | } 127 | 128 | /** 129 | * This parameter specifies the recipient of a multicast message, a message sent to more than one registration token. 130 | * The value should be an array of registration tokens to which to send the multicast message. The array must contain at least 1 and at most 1000 131 | * registration tokens. To send a message to a single device, use the to parameter. 132 | * Multicast messages are only allowed using the HTTP JSON format. 133 | * 134 | * @param array $registrationIds 135 | * @return $this 136 | */ 137 | public function setRegistrationIds($registrationIds) 138 | { 139 | $this->registrationIds = $registrationIds; 140 | 141 | return $this; 142 | } 143 | 144 | /** 145 | * @return string 146 | */ 147 | public function getCondition() 148 | { 149 | return $this->condition; 150 | } 151 | 152 | /** 153 | * [Optional] This parameter specifies a logical expression of conditions that determine the message target. 154 | * Supported condition: Topic, formatted as "'yourTopic' in topics". This value is case-insensitive. 155 | * Supported operators: &&, ||. Maximum two operators per topic message supported. 156 | * 157 | * @param string $condition 158 | * @return $this 159 | */ 160 | public function setCondition($condition) 161 | { 162 | $this->condition = $condition; 163 | 164 | return $this; 165 | } 166 | 167 | /** 168 | * @return string 169 | */ 170 | public function getCollapseKey() 171 | { 172 | return $this->collapseKey; 173 | } 174 | 175 | /** 176 | * [Optional] This parameter identifies a group of messages (e.g., with collapse_key: "Updates Available") that can be collapsed, so that only the last 177 | * message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or 178 | * becomes active. 179 | * Note that there is no guarantee of the order in which messages get sent. 180 | * Note: A maximum of 4 different collapse keys is allowed at any given time. This means a FCM connection server can simultaneously store 4 different 181 | * send-to-sync messages per client app. If you exceed this number, there is no guarantee which 4 collapse keys the FCM connection server will keep. 182 | * 183 | * @param string $collapseKey 184 | * @return $this 185 | */ 186 | public function setCollapseKey($collapseKey) 187 | { 188 | $this->collapseKey = $collapseKey; 189 | 190 | return $this; 191 | } 192 | 193 | /** 194 | * @return bool 195 | */ 196 | public function isContentAvailable() 197 | { 198 | return $this->contentAvailable; 199 | } 200 | 201 | /** 202 | * [Optional] On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an 203 | * inactive client app is awoken. On Android, data messages wake the app by default. On Chrome, currently not supported. 204 | * 205 | * @param bool $contentAvailable 206 | * @return $this 207 | */ 208 | public function setContentAvailable($contentAvailable) 209 | { 210 | $this->contentAvailable = $contentAvailable; 211 | 212 | return $this; 213 | } 214 | 215 | /** 216 | * @return bool 217 | */ 218 | public function isMutableContent() 219 | { 220 | return $this->mutableContent; 221 | } 222 | 223 | /** 224 | * [Optional] Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNS payload. When a notification is sent and 225 | * this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension. This parameter 226 | * will be ignored for Android and web. 227 | * 228 | * @param bool $mutableContent 229 | * @return $this 230 | */ 231 | public function setMutableContent($mutableContent) 232 | { 233 | $this->mutableContent = $mutableContent; 234 | 235 | return $this; 236 | } 237 | 238 | /** 239 | * @return string 240 | */ 241 | public function getPriority() 242 | { 243 | return $this->priority; 244 | } 245 | 246 | /** 247 | * [Optional] Sets the priority of the message. Valid values are "normal" and "high." On iOS, these correspond to APNs priorities 5 and 10. 248 | * By default, notification messages are sent with high priority, and data messages are sent with normal priority. Normal priority optimizes the client 249 | * app's battery consumption and should be used unless immediate delivery is required. For messages with normal priority, the app may receive the message 250 | * with unspecified delay. 251 | * When a message is sent with high priority, it is sent immediately, and the app can wake a sleeping device and open a network connection to your server. 252 | * 253 | * @param string $priority 254 | * @return $this 255 | */ 256 | public function setPriority($priority) 257 | { 258 | $this->priority = $priority; 259 | 260 | return $this; 261 | } 262 | 263 | /** 264 | * @return int 265 | */ 266 | public function getTimeToLive() 267 | { 268 | return $this->timeToLive; 269 | } 270 | 271 | /** 272 | * This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live 273 | * supported is 4 weeks, and the default value is 4 weeks. 274 | * 275 | * @param int $timeToLive 276 | * @return $this 277 | */ 278 | public function setTimeToLive($timeToLive) 279 | { 280 | $this->timeToLive = $timeToLive; 281 | 282 | return $this; 283 | } 284 | 285 | /** 286 | * @return bool 287 | */ 288 | public function isDryRun() 289 | { 290 | return $this->dryRun; 291 | } 292 | 293 | /** 294 | * This parameter, when set to true, allows developers to test a request without actually sending a message. 295 | * 296 | * @param bool $dryRun 297 | * @return $this 298 | */ 299 | public function setDryRun($dryRun) 300 | { 301 | $this->dryRun = $dryRun; 302 | 303 | return $this; 304 | } 305 | 306 | /** 307 | * @return array|object 308 | */ 309 | public function getData() 310 | { 311 | return $this->data; 312 | } 313 | 314 | /** 315 | * [Optional] This parameter specifies the custom key-value pairs of the message's payload. 316 | * For example, with data:{"score":"3x1"}: 317 | * On iOS, if the message is sent via APNS, it represents the custom data fields. If it is sent via FCM connection server, it would be represented as key 318 | * value dictionary in AppDelegate application:didReceiveRemoteNotification:. 319 | * On Android, this would result in an intent extra named score with the string value 3x1. 320 | * The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as 321 | * collapse_key). 322 | * Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. 323 | * 324 | * @param array|object $data 325 | * @return $this 326 | */ 327 | public function setData($data) 328 | { 329 | $this->data = $data; 330 | 331 | return $this; 332 | } 333 | 334 | /** 335 | * @return FcmNotification 336 | */ 337 | public function getNotification() 338 | { 339 | return $this->notification; 340 | } 341 | 342 | /** 343 | * [Optional] This parameter specifies the predefined, user-visible key-value pairs of the notification payload. 344 | * 345 | * @param FcmNotification $notification 346 | * @return $this 347 | */ 348 | public function setNotification($notification) 349 | { 350 | $this->notification = $notification; 351 | 352 | return $this; 353 | } 354 | 355 | /** 356 | * @return string 357 | */ 358 | public function toJson() 359 | { 360 | return json_encode($this->toArray()); 361 | } 362 | 363 | /** 364 | * @return array 365 | */ 366 | public function toArray() 367 | { 368 | $array = [ 369 | 'to' => $this->to, 370 | 'registration_ids' => $this->registrationIds, 371 | 'condition' => $this->condition, 372 | 'collapse_key' => $this->collapseKey, 373 | 'content_available' => $this->contentAvailable, 374 | 'mutable_content' => $this->mutableContent, 375 | 'priority' => $this->priority, 376 | 'time_to_live' => $this->timeToLive, 377 | 'dry_run' => $this->dryRun, 378 | 'data' => $this->data, 379 | ]; 380 | 381 | if ($this->notification) { 382 | $array['notification'] = $this->notification->toArray(); 383 | } 384 | 385 | return $array; 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /src/FcmNotification.php: -------------------------------------------------------------------------------- 1 | title; 83 | } 84 | 85 | /** 86 | * [Optional] The notification's title. 87 | * 88 | * This field is not visible on iOS phones and tablets. 89 | * 90 | * @param string $title 91 | * @return $this 92 | */ 93 | public function setTitle($title) 94 | { 95 | $this->title = $title; 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * @return string 102 | */ 103 | public function getBody() 104 | { 105 | return $this->body; 106 | } 107 | 108 | /** 109 | * [Optional] The notification's body text. 110 | * 111 | * @param string $body 112 | * @return $this 113 | */ 114 | public function setBody($body) 115 | { 116 | $this->body = $body; 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * @return string 123 | */ 124 | public function getClickAction() 125 | { 126 | return $this->clickAction; 127 | } 128 | 129 | /** 130 | * [Optional] 131 | * iOS: 132 | * The action associated with a user click on the notification. 133 | * Corresponds to category in the APNs payload. 134 | * 135 | * Android: 136 | * The action associated with a user click on the notification. 137 | * If specified, an activity with a matching intent filter is launched when a user clicks on the notification. 138 | * 139 | * Web: 140 | * The action associated with a user click on the notification. 141 | * For all URL values, secure HTTPS is required. 142 | * 143 | * @param string $clickAction 144 | * @return $this 145 | */ 146 | public function setClickAction($clickAction) 147 | { 148 | $this->clickAction = $clickAction; 149 | 150 | return $this; 151 | } 152 | 153 | /** 154 | * @return string 155 | */ 156 | public function getAndroidChannelId() 157 | { 158 | return $this->androidChannelId; 159 | } 160 | 161 | /** 162 | * [Optional] The notification's channel id (new in Android O). 163 | * The app must create a channel with this ID before any notification with this key is received. 164 | * If you don't send this key in the request, or if the channel id provided has not yet been created by your app, FCM uses the channel id specified in your app 165 | * manifest. 166 | * 167 | * @param string $androidChannelId 168 | * @return $this 169 | */ 170 | public function setAndroidChannelId($androidChannelId) 171 | { 172 | $this->androidChannelId = $androidChannelId; 173 | 174 | return $this; 175 | } 176 | 177 | /** 178 | * @return string 179 | */ 180 | public function getIcon() 181 | { 182 | return $this->icon; 183 | } 184 | 185 | /** 186 | * [Optional] The notification's icon. 187 | * Sets the notification icon to myicon for drawable resource myicon. If you don't send this key in the request, FCM displays the launcher icon specified in 188 | * your app manifest. 189 | * 190 | * @param string $icon 191 | * @return $this 192 | */ 193 | public function setIcon($icon) 194 | { 195 | $this->icon = $icon; 196 | 197 | return $this; 198 | } 199 | 200 | /** 201 | * @return string 202 | */ 203 | public function getSound() 204 | { 205 | return $this->sound; 206 | } 207 | 208 | /** 209 | * [Optional] The sound to play when the device receives the notification. 210 | * Supports "default" or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/. 211 | * 212 | * @param string $sound 213 | * @return $this 214 | */ 215 | public function setSound($sound) 216 | { 217 | $this->sound = $sound; 218 | 219 | return $this; 220 | } 221 | 222 | /** 223 | * @return string 224 | */ 225 | public function getBadge() 226 | { 227 | return $this->badge; 228 | } 229 | 230 | /** 231 | * [Optional] The value of the badge on the home screen app icon. 232 | * If not specified, the badge is not changed. 233 | * If set to 0, the badge is removed. 234 | * 235 | * @param string $badge 236 | * @return $this 237 | */ 238 | public function setBadge($badge) 239 | { 240 | $this->badge = $badge; 241 | 242 | return $this; 243 | } 244 | 245 | /** 246 | * @return string 247 | */ 248 | public function getTag() 249 | { 250 | return $this->tag; 251 | } 252 | 253 | /** 254 | * [Optional] Identifier used to replace existing notifications in the notification drawer. 255 | * If not specified, each request creates a new notification. 256 | * If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer. 257 | * 258 | * @param string $tag 259 | * @return $this 260 | */ 261 | public function setTag($tag) 262 | { 263 | $this->tag = $tag; 264 | 265 | return $this; 266 | } 267 | 268 | /** 269 | * @return string 270 | */ 271 | public function getColor() 272 | { 273 | return $this->color; 274 | } 275 | 276 | /** 277 | * [Optional] The notification's icon color, expressed in #rrggbb format. 278 | * 279 | * @param string $color 280 | * @return $this 281 | */ 282 | public function setColor($color) 283 | { 284 | $this->color = $color; 285 | 286 | return $this; 287 | } 288 | 289 | /** 290 | * @return string 291 | */ 292 | public function getBodyLocKey() 293 | { 294 | return $this->bodyLocKey; 295 | } 296 | 297 | /** 298 | * [Optional] The key to the body string in the app's string resources to use to localize the body text to the user's current localization. 299 | * 300 | * @param string $bodyLocKey 301 | * @return $this 302 | */ 303 | public function setBodyLocKey($bodyLocKey) 304 | { 305 | $this->bodyLocKey = $bodyLocKey; 306 | 307 | return $this; 308 | } 309 | 310 | /** 311 | * @return array 312 | */ 313 | public function getBodyLocArgs() 314 | { 315 | return $this->bodyLocArgs; 316 | } 317 | 318 | /** 319 | * [Optional] The key to the title string in the app's string resources to use to localize the title text to the user's current localization. 320 | * 321 | * @param array $bodyLocArgs 322 | * @return $this 323 | */ 324 | public function setBodyLocArgs($bodyLocArgs) 325 | { 326 | $this->bodyLocArgs = $bodyLocArgs; 327 | 328 | return $this; 329 | } 330 | 331 | /** 332 | * @return string 333 | */ 334 | public function getTitleLocKey() 335 | { 336 | return $this->titleLocKey; 337 | } 338 | 339 | /** 340 | * [Optional] Variable string values to be used in place of the format specifiers in body_loc_key to use to localize the body text to the user's current 341 | * localization. 342 | * 343 | * @param string $titleLocKey 344 | * @return $this 345 | */ 346 | public function setTitleLocKey($titleLocKey) 347 | { 348 | $this->titleLocKey = $titleLocKey; 349 | 350 | return $this; 351 | } 352 | 353 | /** 354 | * @return array 355 | */ 356 | public function getTitleLocArgs() 357 | { 358 | return $this->titleLocArgs; 359 | } 360 | 361 | /** 362 | * [Optional] Variable string values to be used in place of the format specifiers in title_loc_key to use to localize the title text to the user's current 363 | * localization. 364 | * 365 | * @param array $titleLocArgs 366 | * @return $this 367 | */ 368 | public function setTitleLocArgs($titleLocArgs) 369 | { 370 | $this->titleLocArgs = $titleLocArgs; 371 | 372 | return $this; 373 | } 374 | 375 | /** 376 | * @return array 377 | */ 378 | public function toArray() 379 | { 380 | return [ 381 | 'title' => $this->title, 382 | 'body' => $this->body, 383 | 'click_action' => $this->clickAction, 384 | 'badge' => $this->badge, 385 | 'android_channel_id' => $this->androidChannelId, 386 | 'icon' => $this->icon, 387 | 'sound' => $this->sound, 388 | 'tag' => $this->tag, 389 | 'color' => $this->color, 390 | 'body_loc_key' => $this->bodyLocKey, 391 | 'body_loc_args' => $this->bodyLocArgs, 392 | 'title_loc_key' => $this->titleLocKey, 393 | 'title_loc_args' => $this->titleLocArgs, 394 | ]; 395 | } 396 | } 397 | -------------------------------------------------------------------------------- /src/FcmServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->when(FcmChannel::class) 16 | ->needs(Client::class) 17 | ->give(function () { 18 | return new Client([ 19 | 'base_uri' => config('broadcasting.connections.fcm.url', FcmChannel::DEFAULT_API_URL), 20 | ]); 21 | }); 22 | } 23 | } 24 | --------------------------------------------------------------------------------