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
|
|
|
public function __construct(Message $message) |
29
|
|
|
{ |
30
|
|
|
$this->message = $message; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the notification's delivery channels. |
35
|
|
|
* |
36
|
|
|
* @param mixed $notifiable |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function via($notifiable) |
40
|
|
|
{ |
41
|
|
|
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 [ |
53
|
|
|
'payload' => (new MessageResource($this->message))->resolve(), |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the mail representation of the notification. |
59
|
|
|
* |
60
|
|
|
* @param mixed $notifiable |
61
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
62
|
|
|
*/ |
63
|
|
|
public function toMail($notifiable) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$body = json_encode($this->message->body); |
|
|
|
|
66
|
|
|
$user = $this->message->user(); |
67
|
|
|
|
68
|
|
|
return (new MailMessage) |
69
|
|
|
->subject('New Message from: '.$user->name) |
|
|
|
|
70
|
|
|
->greeting('Hello!') |
71
|
|
|
->line("{$user->name} pinged you!") |
72
|
|
|
->line("{$body}") |
73
|
|
|
->line('Thank you for using our application!'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.