Passed
Push — dev5 ( dcc882...87417d )
by Ron
06:13
created

TechTipCommentsController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Http\Controllers\TechTips;
4
5
use App\User;
6
use App\TechTips;
7
use App\TechTipComments;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Auth;
11
use App\Http\Controllers\Controller;
12
use App\Notifications\NewTechTipComment;
13
use Illuminate\Support\Facades\Notification;
14
15
class TechTipCommentsController extends Controller
16
{
17 8
    public function __construct()
18
    {
19 8
        $this->middleware('auth');
20 8
    }
21
22
    //  Add a new Tech Tip Comment
23 2
    public function store(Request $request)
24
    {
25 2
        $request->validate([
26 2
            'comment' => 'required',
27
            'tipID' => 'required',
28
        ]);
29
30 2
        TechTipComments::create([
31 2
            'tip_id' => $request->tipID,
32 2
            'user_id' => Auth::user()->user_id,
33 2
            'comment' => $request->comment
34
        ]);
35
36 2
        $ownerID = TechTips::find($request->tipID)->user_id;
1 ignored issue
show
Bug introduced by
The property user_id does not exist on App\TechTips. Did you mean user?
Loading history...
37 2
        $owner = User::find($ownerID);
38
39 2
        Notification::send($owner, new NewTechTipComment(Auth::user()->full_name, $request->tipID));
40
41 2
        return response()->json(['success' => true]);
42
    }
43
44
    //  Retrieve the comments for a tech tip
45 2
    public function show($id)
46
    {
47 2
        return TechTipComments::where('tip_id', $id)->with('User')->get();
48
    }
49
50
    //  Delete a comment
51
    public function destroy($id)
52
    {
53
        TechTipComments::find($id)->delete();
54
55
        Log::warning('A Tech Tip Comment (id# '.$id.') was deleted by User ID - '.Auth::user()->user_id);
56
        return response()->json(['success' => true]);
57
    }
58
}
59