NotificationService::sendNotification()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Events\NotificationEvent;
6
use App\Models\UserNotification;
7
8
/**
9
 * Class NotificationService
10
 *
11
 * @package App\Services
12
 */
13
class NotificationService
14
{
15
    /**
16
     * Send notification to user.
17
     *
18
     * @param  UserNotification  $notification
19
     */
20
    public function sendNotification(UserNotification $notification)
21
    {
22
        event(new NotificationEvent($notification->toArray(), $notification->user_id));
23
    }
24
25
    /**
26
     * Add new user notification.
27
     *
28
     * @param $userId
29
     * @param $message
30
     * @param $refName
31
     * @param $refId
32
     *
33
     * @return UserNotification
34
     */
35
    public function addNotification($userId, $message, $refName, $refId)
36
    {
37
        $userNotification = new UserNotification();
38
39
        $userNotification->user_id  = $userId;
40
        $userNotification->message  = $message;
41
        $userNotification->ref_name = $refName;
42
        $userNotification->ref_id   = $refId;
43
        $userNotification->status   = UserNotification::STATUS_UNREAD;
44
45
        $userNotification->save();
46
47
        return $userNotification;
48
    }
49
}
50