1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Notifications; |
4
|
|
|
|
5
|
|
|
use App\Models\TechTip; |
6
|
|
|
use App\Models\TechTipComment; |
7
|
|
|
use App\Models\User; |
8
|
|
|
use App\Models\UserSettingType; |
9
|
|
|
use Illuminate\Bus\Queueable; |
10
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
11
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
12
|
|
|
use Illuminate\Notifications\Notification; |
13
|
|
|
|
14
|
|
|
class NewTechTipCommentNotification extends Notification implements ShouldQueue |
15
|
|
|
{ |
16
|
|
|
use Queueable; |
17
|
|
|
|
18
|
|
|
protected $comment; |
19
|
|
|
protected $user; |
20
|
|
|
protected $tip; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create a new notification instance |
24
|
|
|
*/ |
25
|
|
|
public function __construct(TechTipComment $comment, User $user) |
26
|
|
|
{ |
27
|
|
|
$this->comment = $comment; |
28
|
|
|
$this->user = $user; |
29
|
|
|
$this->tip = TechTip::find($comment->tip_id); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the notification's delivery channels |
34
|
|
|
*/ |
35
|
|
|
public function via($notifiable) |
36
|
|
|
{ |
37
|
|
|
$settingId = UserSettingType::where('name', 'Receive Email Notifications')->first()->setting_type_id; |
38
|
|
|
$allow = $notifiable->UserSetting->where('setting_type_id', $settingId)->first()->value; |
39
|
|
|
|
40
|
|
|
if($allow) |
41
|
|
|
{ |
42
|
|
|
return ['mail', 'database']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return ['database']; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the mail representation of the notification |
50
|
|
|
*/ |
51
|
|
|
public function toMail($notifiable) |
52
|
|
|
{ |
53
|
|
|
return (new MailMessage) |
54
|
|
|
->subject('Someone Commented On A Tech Tip') |
55
|
|
|
->greeting('Hello '.$notifiable->full_name) |
56
|
|
|
->line($this->user->full_name.' has commented on Tech Tip - .'.$this->tip->subject) |
57
|
|
|
->line('The comment is: ') |
58
|
|
|
->line($this->comment->comment) |
59
|
|
|
->action('Click Here to review the comment', url(route('tech-tips.show', $this->tip->slug))); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the array representation of the notification |
64
|
|
|
*/ |
65
|
|
|
public function toArray($notifiable) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'subject' => 'New Tech Tip Comment', |
69
|
|
|
'data' => [ |
70
|
|
|
'tip' => $this->tip, |
71
|
|
|
'comment' => $this->comment, |
72
|
|
|
'user' => $this->user, |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.