File size: 1,322 Bytes
52d9fb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Comment;
use Illuminate\Http\Request;

class CommentController extends Controller
{
    public function index($authorId = 0)
    {
        $pageTitle = 'Comments';
        $comments  = Comment::where('review_id', 0)->with(['user', 'product']);
        if($authorId){
            $comments = $comments->where('user_id', $authorId);
        }
        $comments = $comments->paginate(getPaginate());
        return view('admin.comment.index', compact('pageTitle', 'comments'));
    }

    public function destroy($id) {
        $comment  = Comment::findOrFail($id);
        $comment->delete();
        $notify[] = ['success', 'Comment deleted'];
        return back()->withNotify($notify);
    }

    public function repliesList($commentId) {
        $pageTitle = 'Replies';
        $comment   = Comment::findOrFail($commentId);
        $replies   = $comment->replies()->with(['user', 'product'])->paginate(getPaginate());
        return view('admin.comment.reply.index', compact('pageTitle', 'replies'));
    }

    public function deleteReply($id) {
        $comment  = Comment::findOrFail($id);
        $comment->delete();
        $notify[] = ['success','Reply deleted'];
        return back()->withNotify($notify);
    }
}