1
|
|
|
<?php namespace jlourenco\comments\Controllers; |
2
|
|
|
|
3
|
|
|
use App\Http\Requests; |
4
|
|
|
use App\Http\Controllers\Controller; |
5
|
|
|
use Blog; |
6
|
|
|
use Sentinel; |
7
|
|
|
use Searchy; |
8
|
|
|
use Input; |
9
|
|
|
use Comments; |
10
|
|
|
use Base; |
11
|
|
|
use Lang; |
12
|
|
|
use Redirect; |
13
|
|
|
|
14
|
|
|
class CommentsController extends Controller |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Delete Confirm |
19
|
|
|
* |
20
|
|
|
* @param int $id |
21
|
|
|
* @return View |
22
|
|
|
*/ |
23
|
|
|
public function getModalDelete($id = null) |
24
|
|
|
{ |
25
|
|
|
$confirm_route = $error = null; |
26
|
|
|
|
27
|
|
|
$title = 'Delete comment'; |
28
|
|
|
$message = 'Are you sure to delete this comment?'; |
29
|
|
|
|
30
|
|
|
// Get post information |
31
|
|
|
$comment = Comments::getCommentsRepository()->findOrFail($id); |
32
|
|
|
|
33
|
|
|
if ($comment == null) |
34
|
|
|
{ |
35
|
|
|
// Prepare the error message |
36
|
|
|
$error = Lang::get('comments.comment.not_found'); |
37
|
|
|
return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$confirm_route = route('delete/comment', ['id' => $comment->id]); |
41
|
|
|
return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Delete the given comment. |
46
|
|
|
* |
47
|
|
|
* @param int $id |
48
|
|
|
* @return Redirect |
49
|
|
|
*/ |
50
|
|
|
public function getDelete($id = null) |
51
|
|
|
{ |
52
|
|
|
// Get comment information |
53
|
|
|
$comment = Comments::getCommentsRepository()->find($id); |
54
|
|
|
|
55
|
|
|
if ($comment == null) |
56
|
|
|
{ |
57
|
|
|
// Prepare the error message |
58
|
|
|
$error = Lang::get('comments.comment.not_found'); |
59
|
|
|
|
60
|
|
|
// Redirect to the post management page |
61
|
|
|
return Redirect::route('posts')->with('error', $error); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
Base::Log('Comment (' . $comment->id . ') was deleted.'); |
65
|
|
|
|
66
|
|
|
// Delete the post |
67
|
|
|
$comment->delete(); |
68
|
|
|
|
69
|
|
|
// Prepare the success message |
70
|
|
|
$success = Lang::get('comments.comment.deleted'); |
71
|
|
|
|
72
|
|
|
// Redirect to the post management page |
73
|
|
|
return Redirect::back()->with('success', $success); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|