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; |
|
|
|
|
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
|
|
|
|