Completed
Branch dev4 (2f299a)
by Ron
08:25
created

NewFileUploaded::toMail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Notifications\Messages\MailMessage;
9
10
class NewFileUploaded extends Notification
11
{
12
    use Queueable;
13
    
14
    protected $details;
15
16
    //  constructor receives the file link details
17
    public function __construct($details)
18
    {
19
        $this->details = $details;
20
    }
21
22
    //  Notification is sent via email and dashboard notification
23
    public function via($notifiable)
24
    {
25
        return ['mail', 'database'];
26
    }
27
28
    //  Email to link owner
29
    public function toMail($notifiable)
30
    {
31
        return (new MailMessage)
32
                    ->line('A new file has been uploaded to the file link - '.$this->details->link_name)
33
                    ->action('Click to View Link', 
34
                             url(route('links.info', [
35
                                 'id' => $this->details->link_id, 
36
                                 'name' => urlencode($this->details->link_name)
37
                            ])));
38
    }
39
40
    //  Dashboard notification
41
    public function toArray($notifiable)
42
    {
43
        return [
44
            'type'    => 'warning',
45
            'message' => 'New File Uploaded to link - '.$this->details->link_name,
46
            'link'    => url(route('links.info', [
47
                                 'id' => $this->details->link_id, 
48
                                 'name' => urlencode($this->details->link_name)
49
                            ]))
50
        ];
51
    }
52
}
53