|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Xetaravel\Notifications; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Bus\Queueable; |
|
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
9
|
|
|
use Illuminate\Notifications\Notification; |
|
10
|
|
|
use Xetaravel\Models\BlogArticle; |
|
11
|
|
|
use Xetaravel\Models\BlogComment; |
|
12
|
|
|
use Xetaravel\Models\DiscussPost; |
|
13
|
|
|
use Xetaravel\Models\Model; |
|
14
|
|
|
|
|
15
|
|
|
class MentionNotification extends Notification implements ShouldQueue |
|
16
|
|
|
{ |
|
17
|
|
|
use Queueable; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The model instance. |
|
21
|
|
|
* |
|
22
|
|
|
* @var Model |
|
23
|
|
|
*/ |
|
24
|
|
|
public Model $model; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new notification instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @param Model $model |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Model $model) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->model = $model; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Parse the instance of the model and build the array. |
|
38
|
|
|
* |
|
39
|
|
|
* @param array $data |
|
40
|
|
|
* |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function parseInstance(array $data = []): array |
|
44
|
|
|
{ |
|
45
|
|
|
$model = $this->model; |
|
46
|
|
|
|
|
47
|
|
|
switch (true) { |
|
48
|
|
|
case $model instanceof DiscussPost: |
|
49
|
|
|
$data['message'] = '<strong>@%s</strong> has mentioned your name in his post !'; |
|
50
|
|
|
$data['link'] = $model->post_url; |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
break; |
|
53
|
|
|
|
|
54
|
|
|
case $model instanceof BlogComment: |
|
55
|
|
|
$data['message'] = '<strong>@%s</strong> has mentioned your name in his comment !'; |
|
56
|
|
|
$data['link'] = $model->comment_url; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
break; |
|
59
|
|
|
|
|
60
|
|
|
case $model instanceof BlogArticle: |
|
61
|
|
|
$data['message'] = '<strong>@%s</strong> has mentioned your name in his article !'; |
|
62
|
|
|
$data['link'] = $model->show_url; |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
break; |
|
65
|
|
|
} |
|
66
|
|
|
$data['message'] = sprintf($data['message'], $model->user->username); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $data; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the notification's delivery channels. |
|
73
|
|
|
* |
|
74
|
|
|
* @param mixed $notifiable |
|
75
|
|
|
* |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function via(mixed $notifiable): array |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
return ['database']; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the array representation of the notification. |
|
85
|
|
|
* |
|
86
|
|
|
* @param mixed $notifiable |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
public function toDatabase(mixed $notifiable): array |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
return $this->parseInstance(['type' => 'mention']); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.