Completed
Push — development ( 41ee4c...b84b55 )
by Ashutosh
10:19
created

CommentController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\User;
4
5
use App\User;
6
use Bugsnag;
7
use App\Comment;
8
use Illuminate\Http\Request;
9
use App\Http\Controllers\Controller;
10
11
class CommentController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware('auth');
16
        $this->middleware('admin');
17
18
        $user = new User();
19
        $this->user = $user;
20
21
        $comment = new Comment();
22
        $this->comment = $comment;
23
    }
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index()
30
    {
31
        //
32
    }
33
34
    /**
35
     * Show the form for creating a new resource.
36
     *
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function create()
40
    {
41
        //
42
    }
43
44
    /**
45
     * Store a newly created resource in storage.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function store(Request $request)
51
    {
52
        try {
53
            $comments = $this->comment->fill($request->input())->save();
54
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
55
            
56
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\User\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
57
             app('log')->error($ex->getMessage());
58
            Bugsnag::notifyException($ex);
59
            return redirect()->back()->with('fails', $ex->getMessage());
60
        }
61
    }
62
63
 
64
65
66
    /**
67
     * Update the specified resource in storage.
68
     *
69
     * @param  \Illuminate\Http\Request  $request
70
     * @param  int  $id
71
     * @return \Illuminate\Http\Response
72
     */
73
    public function update(Request $request, $id)
74
    {
75
      try {
76
             $comment = $this->comment->where('id',$id)->update(['user_id'=>$request->input('user_id'),
77
            'updated_by_user_id'=>$request->input('updated_by_user_id'),'description'=>$request->input('description')]);
78
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
79
        } catch (Exception $ex) {
80
             app('log')->error($ex->getMessage());
81
            Bugsnag::notifyException($ex);
82
            return redirect()->back()->with('fails', $ex->getMessage());
83
        }
84
       
85
    }
86
87
    /**
88
     * Remove the specified resource from storage.
89
     *
90
     * @param  int  $id
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function destroy($id)
94
    {
95
        try {
96
             $delComment = $this->comment->where('id',$id)->delete();
97
         return redirect()->back()->with('success', \Lang::get('message.deleted-successfully'));
98
            
99
        } catch (Exception $e) {
100
            app('log')->error($ex->getMessage());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ex seems to be never defined.
Loading history...
101
            Bugsnag::notifyException($ex);
102
            return redirect()->back()->with('fails', $ex->getMessage());
103
        }
104
       
105
    }
106
}
107