|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\TechTips; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\TechTipComment; |
|
6
|
|
|
use App\Events\NewTipCommentEvent; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
use App\Http\Requests\TechTips\CommentRequest; |
|
9
|
|
|
|
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use Illuminate\Support\Facades\Log; |
|
12
|
|
|
use Illuminate\Support\Facades\Auth; |
|
13
|
|
|
|
|
14
|
|
|
class CommentController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Store a new comment on a Tech Tip |
|
18
|
|
|
*/ |
|
19
|
|
|
public function store(CommentRequest $request) |
|
20
|
|
|
{ |
|
21
|
|
|
TechTipComment::create([ |
|
22
|
|
|
'tip_id' => $request->tip_id, |
|
23
|
|
|
'user_id' => $request->user()->user_id, |
|
24
|
|
|
'comment' => $request->comment, |
|
25
|
|
|
]); |
|
26
|
|
|
|
|
27
|
|
|
// event(new EventsTechTipComment($request->tip_id, $request->comment)); |
|
28
|
|
|
event(new NewTipCommentEvent($request->tip_id, $request->comment, $request->user()->full_name)); |
|
29
|
|
|
|
|
30
|
|
|
Log::info('New comment has been created on Tech Tip ID '.$request->tip_id.' by '.$request->user()->username); |
|
31
|
|
|
return back()->with(['message' => 'Comment submitted', 'type' => 'success']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Display the specified resource. |
|
36
|
|
|
* |
|
37
|
|
|
* @param int $id |
|
38
|
|
|
* @return \Illuminate\Http\Response |
|
39
|
|
|
*/ |
|
40
|
|
|
// public function show($id) |
|
41
|
|
|
// { |
|
42
|
|
|
// // |
|
43
|
|
|
// } |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Update the specified resource in storage. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Illuminate\Http\Request $request |
|
49
|
|
|
* @param int $id |
|
50
|
|
|
* @return \Illuminate\Http\Response |
|
51
|
|
|
*/ |
|
52
|
|
|
// public function update(Request $request, $id) |
|
53
|
|
|
// { |
|
54
|
|
|
// // |
|
55
|
|
|
// } |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Delete a comment |
|
59
|
|
|
*/ |
|
60
|
|
|
public function destroy($id) |
|
61
|
|
|
{ |
|
62
|
|
|
$comment = TechTipComment::findOrFail($id); |
|
63
|
|
|
|
|
64
|
|
|
$this->authorize('delete', $comment); |
|
65
|
|
|
$comment->delete(); |
|
66
|
|
|
|
|
67
|
|
|
Log::info('A Comment on Tech Tip ID '.$comment->tip_id.' has been deleted by '.Auth::user()->username.'. Comment ID - '.$comment->id); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
return back()->with(['message' => 'Comment has been deleted', 'type' => 'danger']); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|