|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Notifications; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Resources\MessageResource; |
|
6
|
|
|
use App\Models\Message; |
|
7
|
|
|
use Illuminate\Bus\Queueable; |
|
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
9
|
|
|
use Illuminate\Notifications\Messages\BroadcastMessage; |
|
10
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
|
11
|
|
|
use Illuminate\Notifications\Notification; |
|
12
|
|
|
|
|
13
|
|
|
class MessageCreated extends Notification implements ShouldQueue |
|
14
|
|
|
{ |
|
15
|
|
|
use Queueable; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Message |
|
19
|
|
|
*/ |
|
20
|
|
|
public Message $message; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Create a new notification instance. |
|
24
|
|
|
* |
|
25
|
|
|
* @param Message $message |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
10 |
|
public function __construct(Message $message) |
|
29
|
|
|
{ |
|
30
|
10 |
|
$this->message = $message; |
|
31
|
10 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get the notification's delivery channels. |
|
35
|
|
|
* |
|
36
|
|
|
* @param mixed $notifiable |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
10 |
|
public function via($notifiable) |
|
40
|
|
|
{ |
|
41
|
10 |
|
return $notifiable->notify_via; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the array representation of the notification. |
|
46
|
|
|
* |
|
47
|
|
|
* @param mixed $notifiable |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function toArray($notifiable) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
return (new MessageResource($this->message))->resolve(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the broadcastable representation of the notification. |
|
57
|
|
|
* |
|
58
|
|
|
* @param mixed $notifiable |
|
59
|
|
|
* @return BroadcastMessage |
|
60
|
|
|
*/ |
|
61
|
|
|
public function toBroadcast($notifiable) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
return new BroadcastMessage( |
|
64
|
|
|
(new MessageResource($this->message))->resolve() |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the mail representation of the notification. |
|
70
|
|
|
* |
|
71
|
|
|
* @param mixed $notifiable |
|
72
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
|
73
|
|
|
*/ |
|
74
|
|
|
public function toMail($notifiable) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$body = json_encode($this->message->body); |
|
|
|
|
|
|
77
|
|
|
$user = $this->message->user(); |
|
78
|
|
|
|
|
79
|
|
|
return (new MailMessage) |
|
80
|
|
|
->subject('New Message from: '.$user->name) |
|
|
|
|
|
|
81
|
|
|
->greeting('Hello!') |
|
82
|
|
|
->line("{$user->name} pinged you!") |
|
83
|
|
|
->line("{$body}") |
|
84
|
|
|
->line('Thank you for using our application!'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.