Passed
Push — dev5a ( 915c64...c2cba2 )
by Ron
07:58
created

SetTipComments::deleteComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Domains\TechTips;
4
5
use App\Notifications\NewTechTipCommentNotification;
6
use App\TechTipComments;
7
use App\TechTips;
8
use App\User;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\Log;
11
use Illuminate\Support\Facades\Notification;
12
13
class SetTipComments
14
{
15 4
    public function createTipComment($request, $user)
16
    {
17 4
        TechTipComments::create([
18 4
            'tip_id' => $request->tip_id,
19 4
            'user_id' => $user->user_id,
20 4
            'comment' => $request->comment,
21
        ]);
22
23
        //  Notify the tip owner and others who have commented or updated the Tech Tip
24 4
        $owners = TechTips::select(['user_id', 'updated_id'])->where('tip_id', $request->tip_id)->first();
25 4
        $others = TechTipComments::select('user_id')->where('tip_id', $request->tip_id)->get();
26
27
        $userList = [
28 4
            User::find($owners->user_id),
0 ignored issues
show
Bug introduced by
The property user_id does not exist on App\TechTips. Did you mean user?
Loading history...
29 4
            User::find($owners->updated_id),
0 ignored issues
show
Bug introduced by
The property updated_id does not exist on App\TechTips. Did you mean updated_at?
Loading history...
30
        ];
31 4
        foreach($others as $o)
32
        {
33 4
            $userList[] = User::find($o->user_id);
34
        }
35
36 4
        Notification::send($userList, new NewTechTipCommentNotification($user->full_name, $request->tip_id));
37
38 4
        return true;
39
    }
40
41 4
    public function deleteComment($commentID)
42
    {
43 4
        TechTipComments::find($commentID)->delete();
44 4
        return true;
45
    }
46
}
47