Passed
Push — dev6 ( 10677b...04df47 )
by Ron
16:49
created

UpdatedEquipmentNotification   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A via() 0 11 2
A __construct() 0 3 1
A toArray() 0 7 1
A toMail() 0 8 1
1
<?php
2
3
namespace App\Notifications\Customers;
4
5
use App\Models\Customer;
6
use App\Models\UserSettingType;
7
8
use Illuminate\Bus\Queueable;
9
use Illuminate\Notifications\Notification;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Notifications\Messages\MailMessage;
12
13
class UpdatedEquipmentNotification extends Notification implements ShouldQueue
14
{
15
    use Queueable;
16
17
    protected $cust;
18
19
    /**
20
     * Create a new notification instance
21
     */
22
    public function __construct(Customer $cust)
23
    {
24
        $this->cust = $cust;
25
    }
26
27
    /**
28
     * Get the notification's delivery channels
29
     */
30
    public function via($notifiable)
31
    {
32
        $settingId = UserSettingType::where('name', 'Receive Email Notifications')->first()->setting_type_id;
33
        $allow     = $notifiable->UserSetting->where('setting_type_id', $settingId)->first()->value;
34
35
        if($allow)
36
        {
37
            return ['mail', 'database'];
38
        }
39
40
        return ['database'];
41
    }
42
43
    /**
44
     * Get the mail representation of the notification
45
     */
46
    public function toMail($notifiable)
47
    {
48
        return (new MailMessage)
49
                    ->subject('Customer Equipment Has Been Updated')
50
                    ->greeting('Hello '.$notifiable->full_name)
51
                    ->line('Customer Equipment was just updated for '.$this->cust->name)
52
                    ->action('Click Here to view the Customer', url(route('customers.show', $this->cust->slug)))
53
                    ->line('Note: You are receiving this notification because this customer is Bookmarked as a Favorite');
54
    }
55
56
    /**
57
     * Get the array representation of the notification
58
     */
59
    public function toArray()
60
    {
61
        return [
62
            'subject' => 'Customer Equipment Has Been Updated',
63
            'data'    => [
64
                'customer' => $this->cust->name,
65
                'slug'     => $this->cust->slug,
66
            ],
67
        ];
68
    }
69
}
70