|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\TechTips; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use App\Models\TechTip; |
|
9
|
|
|
use App\Models\TechTipComment; |
|
10
|
|
|
use App\Events\TechTips\TechTipCommentCreatedEvent; |
|
11
|
|
|
use App\Events\TechTips\TechTipCommentDeletedEvent; |
|
12
|
|
|
use App\Events\TechTips\TechTipCommentFlaggedEvent; |
|
13
|
|
|
use App\Events\TechTips\TechTipCommentUpdatedEvent; |
|
14
|
|
|
use App\Http\Requests\TechTips\TechTipCommentRequest; |
|
15
|
|
|
use App\Http\Requests\TechTips\UpdateCommentRequest; |
|
16
|
|
|
|
|
17
|
|
|
class TechTipCommentsController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Store a newly created Tech Tip Comment |
|
21
|
|
|
*/ |
|
22
|
|
|
public function store(TechTipCommentRequest $request) |
|
23
|
|
|
{ |
|
24
|
|
|
$comment = TechTipComment::create([ |
|
25
|
|
|
'tip_id' => $request->tip_id, |
|
26
|
|
|
'user_id' => $request->user()->user_id, |
|
27
|
|
|
'comment' => $request->comment, |
|
28
|
|
|
]); |
|
29
|
|
|
|
|
30
|
|
|
event(new TechTipCommentCreatedEvent($comment)); |
|
31
|
|
|
return TechTipComment::where('tip_id', $request->tip_id)->with('User')->get(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the comments for a specific Tech Tip |
|
36
|
|
|
*/ |
|
37
|
|
|
public function show($id) |
|
38
|
|
|
{ |
|
39
|
|
|
return TechTip::where('tip_id', $id)->get(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Edit function will flag a Tech Tip as innapropriate |
|
44
|
|
|
*/ |
|
45
|
|
|
public function edit($id) |
|
46
|
|
|
{ |
|
47
|
|
|
$comment = TechTipComment::find($id); |
|
48
|
|
|
$comment->update(['flagged' => true]); |
|
49
|
|
|
|
|
50
|
|
|
event(new TechTipCommentFlaggedEvent($comment)); |
|
|
|
|
|
|
51
|
|
|
return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Update a Tech Tip Comment |
|
56
|
|
|
*/ |
|
57
|
|
|
public function update(UpdateCommentRequest $request, $id) |
|
58
|
|
|
{ |
|
59
|
|
|
$comment = TechTipComment::find($id); |
|
60
|
|
|
$comment->update($request->only(['comment'])); |
|
61
|
|
|
$comment->save(); |
|
62
|
|
|
|
|
63
|
|
|
event(new TechTipCommentUpdatedEvent($comment)); |
|
|
|
|
|
|
64
|
|
|
return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Delete the Tech Tip Comment |
|
69
|
|
|
*/ |
|
70
|
|
|
public function destroy($id) |
|
71
|
|
|
{ |
|
72
|
|
|
$comment = TechTipComment::find($id); |
|
73
|
|
|
$this->authorize('delete', $comment); |
|
74
|
|
|
$comment->delete(); |
|
75
|
|
|
|
|
76
|
|
|
event(new TechTipCommentDeletedEvent($comment)); |
|
|
|
|
|
|
77
|
|
|
return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|