|
1
|
|
|
<?php namespace App\Modules\V1\Notifications\Repositories; |
|
2
|
|
|
|
|
3
|
|
|
use App\Modules\V1\Core\AbstractRepositories\AbstractRepository; |
|
4
|
|
|
use LaravelFCM\Message\OptionsBuilder; |
|
5
|
|
|
use LaravelFCM\Message\PayloadDataBuilder; |
|
6
|
|
|
use LaravelFCM\Message\PayloadNotificationBuilder; |
|
7
|
|
|
|
|
8
|
|
|
class PushNotificationDeviceRepository extends AbstractRepository |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Return the model full namespace. |
|
12
|
|
|
* |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function getModel() |
|
16
|
|
|
{ |
|
17
|
|
|
return 'App\Modules\V1\Notifications\PushNotificationDevice'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Register the given device to the logged in user. |
|
22
|
|
|
* |
|
23
|
|
|
* @param string $data |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function registerDevice($data) |
|
27
|
|
|
{ |
|
28
|
|
|
$data['access_token'] = \Auth::user()->token(); |
|
29
|
|
|
$data['user_id'] = \Auth::id(); |
|
30
|
|
|
if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) |
|
31
|
|
|
{ |
|
32
|
|
|
$data['id'] = $device->id; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $this->save($data); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Generate the given message data. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $title |
|
42
|
|
|
* @param string $message |
|
43
|
|
|
* @param string $data |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
public function generateMessageData($title, $message, $data = []) |
|
47
|
|
|
{ |
|
48
|
|
|
$optionBuilder = new OptionsBuilder(); |
|
49
|
|
|
$notificationBuilder = new PayloadNotificationBuilder($title); |
|
50
|
|
|
$dataBuilder = new PayloadDataBuilder(); |
|
51
|
|
|
|
|
52
|
|
|
$optionBuilder->setTimeToLive(60*20); |
|
53
|
|
|
$notificationBuilder->setBody($message); |
|
54
|
|
|
$dataBuilder->addData($data); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$options = $optionBuilder->build(); |
|
57
|
|
|
$notification = $notificationBuilder->build(); |
|
58
|
|
|
$data = $dataBuilder->build(); |
|
59
|
|
|
|
|
60
|
|
|
return compact('options', 'notification', 'data'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: